Sys.Date()[1] "2023-03-16"
2023-01-27
Sys.Date()[1] "2023-03-16"
getwd()[1] "/media/jstevens/data/jstevens/OneDrive/active_sync/projects/dpavir_2023/slides"
Note
If you give argument values in correct order, you don’t need to include argument names. But it’s usually a good idea anyway.
# the best way
x <- 9
# avoid this
y = 10
# definitely don't do this
11 -> zNote
You can assign multiple objects at the same time:
# chain assignments of the same value to different objects
a <- b <- c <- 0x <- 9 # assign value 9 to object xx # print contents of object x to console[1] 9
(x <- 9) # add parentheses to print to console when assigning[1] 9
mean1=mean (x[1,4:10],na.rm=T)+0.5mean1 <- mean(x[1, 4:10], na.rm = TRUE) + 0.5Use <- as assignment operator
Use space between operators (*, =, ==) and after commas
Write out TRUE and FALSE
Do not use space between function and parentheses
Use indents to separate nested components (Ctrl+I)
Use ", not ', for quoting text unless it already contains double quotes
Be nice to machines
Be nice to humans
Make sorting and searching easy
my_file.R not My filé$.R
foo.R and Foo.R
expt1_cond2_subj114.csvx) but not too descriptive (this_is_my_object)a ≠ A)prelim_analysis_expt1.RYYYY-MM-DD
2021-04-06_prelim_analysis_expt1.Rmdprelim_analysis_expt1_2021-04-06.Rmd01_preface.Rmd02_introduction.Rmd