I have a couple of RStudio projects that I've set up to automate tasks like grading multiple choice tests. The functions necessary to do the tasks are just saved in a text file, and to make sure they're available to me or other users I've been using an .Rprofile
file that just runs something like source("MyFunctions.R")
on startup. If an .Rprofile
file is in the base directory of an RStudio project, it's automatically run when opening the project
However, I've run into occasional errors where functions provided by the base R packages aren't loaded before the script is sourced, functions like read.csv
or installed.packages
, e.g.:
Error in eval(expr, envir, enclos) :
could not find function "installed.packages"
Is there some way to wait for the default packages to load before source()
is run, rather than adding explicit library()
calls for all the default packages that fail to load?