I believe I have found an incorrect statement in the documentation of the defaultPackages
option. In R 4.2.0, it reads (on pg. 438 of fullrefman.pdf
)
‘defaultPackages’: the packages that are attached by default when
R starts up. Initially set from value of the environment
variable ‘R_DEFAULT_PACKAGES’, or if that is unset to
‘c("datasets", "utils", "grDevices", "graphics", "stats",
"methods")’. (Set ‘R_DEFAULT_PACKAGES’ to ‘NULL’ or a
comma-separated list of package names.) It will not work to
set this in a .Rprofile file, as its value is consulted
before that file is read.
My question concerns the last sentence - actual behavior in R 3.4+ seems to contradict this. Here is a Dockerfile to demonstrate
# Dockerfile
FROM rocker/tidyverse
RUN echo "Example 1: Regular defaultPackages" | tee -a out.log
RUN R --quiet -e "search()" | tee -a out.log
RUN echo "Example 2: defaultPackages set to empty" | tee -a out.log
RUN echo "options(defaultPackages = c())" | tee ~/.Rprofile
RUN R --quiet -e "search()" | tee -a out.log
RUN echo "Example 3: defaultPackages appended with tidyverse" | tee -a out.log
RUN echo "options(defaultPackages = c(getOption('defaultPackages'), 'tidyverse'))" | tee ~/.Rprofile
RUN R --quiet -e "search()" | tee -a out.log
CMD cat out.log
# out.log
Example 1: Regular defaultPackages
> search()
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:utils" "package:datasets"
[7] "package:methods" "Autoloads" "package:base"
>
>
Example 2: defaultPackages set to empty
> search()
[1] ".GlobalEnv" "package:methods" "Autoloads" "package:base"
>
>
Example 3: defaultPackages appended with tidyverse
> search()
[1] ".GlobalEnv" "package:forcats" "package:stringr"
[4] "package:dplyr" "package:purrr" "package:readr"
[7] "package:tidyr" "package:tibble" "package:ggplot2"
[10] "package:tidyverse" "package:stats" "package:graphics"
[13] "package:grDevices" "package:utils" "package:datasets"
[16] "package:methods" "Autoloads" "package:base"
Am I misunderstanding something?