Set up an R script

MDA 2020, GDC Nik Zemp, January 2020, Version 0.1

Set working directory (not needed in a R project)

#setwd("~/Desktop/")

Remove all variables

rm(list = ls())

set seed

set.seed(1000)

load packages

library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.3
## ✓ tidyr   1.0.0     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Source functions

source("My_Functions.R")

sessionInfo

sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] phyloseq_1.28.0 forcats_0.4.0   stringr_1.4.0   dplyr_0.8.3    
##  [5] purrr_0.3.3     readr_1.3.1     tidyr_1.0.0     tibble_2.1.3   
##  [9] ggplot2_3.2.1   tidyverse_1.3.0
## 
## loaded via a namespace (and not attached):
##  [1] Biobase_2.44.0      httr_1.4.1          splines_3.6.0      
##  [4] jsonlite_1.6        foreach_1.4.7       modelr_0.1.5       
##  [7] assertthat_0.2.1    stats4_3.6.0        cellranger_1.1.0   
## [10] yaml_2.2.0          pillar_1.4.3        backports_1.1.5    
## [13] lattice_0.20-38     glue_1.3.1          digest_0.6.23      
## [16] XVector_0.24.0      rvest_0.3.5         colorspace_1.4-1   
## [19] htmltools_0.4.0     Matrix_1.2-18       plyr_1.8.5         
## [22] pkgconfig_2.0.3     broom_0.5.3         haven_2.2.0        
## [25] zlibbioc_1.30.0     scales_1.1.0        mgcv_1.8-31        
## [28] generics_0.0.2      IRanges_2.18.3      withr_2.1.2        
## [31] BiocGenerics_0.30.0 lazyeval_0.2.2      cli_2.0.1          
## [34] survival_3.1-8      magrittr_1.5        crayon_1.3.4       
## [37] readxl_1.3.1        evaluate_0.14       fs_1.3.1           
## [40] fansi_0.4.1         nlme_3.1-143        MASS_7.3-51.5      
## [43] xml2_1.2.2          vegan_2.5-6         data.table_1.12.8  
## [46] tools_3.6.0         hms_0.5.3           lifecycle_0.1.0    
## [49] Rhdf5lib_1.6.3      S4Vectors_0.22.1    munsell_0.5.0      
## [52] reprex_0.3.0        cluster_2.1.0       Biostrings_2.52.0  
## [55] ade4_1.7-13         compiler_3.6.0      rlang_0.4.2        
## [58] rhdf5_2.28.1        grid_3.6.0          iterators_1.0.12   
## [61] biomformat_1.12.0   rstudioapi_0.10     igraph_1.2.4.2     
## [64] rmarkdown_2.1       multtest_2.40.0     gtable_0.3.0       
## [67] codetools_0.2-16    DBI_1.1.0           reshape2_1.4.3     
## [70] R6_2.4.1            lubridate_1.7.4     knitr_1.27         
## [73] zeallot_0.1.0       permute_0.9-5       ape_5.3            
## [76] stringi_1.4.5       parallel_3.6.0      Rcpp_1.0.3         
## [79] vctrs_0.2.1         dbplyr_1.4.2        tidyselect_0.2.5   
## [82] xfun_0.12

##use functions

plot_points(1000)

se(iris$Sepal.Length)
## [1] 0.06761132

## [1] 0.06761132

save specific objects to a file

save(iris, file = "iris.RData")

load object

 load("iris.RData")

save workspace

save.image(file = "image.RData")

load workspace

load("image.RData")

Use Styler

# datawox=jittermap(datawox, amount = 1e-6);datauto=jittermap(datauto, amount = 1e-6);data= jittermap(data, amount = 1e-6);data2 <- data;datauto$pheno$gender <- as.numeric(datauto$pheno$gender)
# datauto$pheno$ffd[68] <- NA;datauto$pheno$ffd <- (datauto$pheno$ffd-min(datauto$pheno$ffd, na.rm = T))/(max(datauto$pheno$ffd,na.rm=T)-min(datauto$pheno$ffd, na.rm = T));datauto$pheno$ffd <- asin(sqrt(datauto$pheno$ffd));datauto$pheno$ffd_height <- log(datauto$pheno$ffd_height);datauto$pheno$open_flowers_ffd5 <- sqrt(datauto$pheno$open_flowersffd5);datauto$pheno$open_flowers_rate= log(datauto$pheno$open_flowers_rate)