Sys.Date()
[1] "2024-03-13"
2023-01-27
Sys.Date()
[1] "2024-03-13"
getwd()
[1] "/media/jstevens/data/jstevens/OneDrive/active_sync/teach/psyc_971--data_science_visualization_in_r/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 -> z
Note
You can assign multiple objects at the same time:
# chain assignments of the same value to different objects
a <- b <- c <- 0
x <- 9 # assign value 9 to object x
x # 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.5
mean1 <- mean(x[1, 4:10], na.rm = TRUE) + 0.5
Use <-
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.csv
x
) but not too descriptive (this_is_my_object
)a ≠ A
)prelim_analysis_expt1.R
YYYY-MM-DD
2021-04-06_prelim_analysis_expt1.Rmd
prelim_analysis_expt1_2021-04-06.Rmd
01_preface.Rmd
02_introduction.Rmd