I want R to load a certain file on initialization, so naturally I added a source
command to my Rprofile so:
.First <- function()
{
cat("\n Welcome to R MotherFnorder!!!\n\n")
setwd("/home/username/Code/R/")
source("/home/username/Code/R/file.R")
}
But now when I start R
it throws a 'function not found' error for default functions like runif
or rnorm
. When I load the same file manually into the workspace I get no errors.
You don't need (or, really, want) to create a .First
. If you put those lines into your .Rprofile
they'll execute just fine. -- With the proviso @Pascal pointed out, that any function called in your file.R
must have its library loaded first. So,
near the bottom of your .Rprofile
, just put
library(whatever_packages_needed)
cat("\n Welcome to R MotherFnorder!!!\n\n")
setwd("/home/username/Code/R/")
source("/home/username/Code/R/file.R")
EDIT: I cannot reproduce your problem. I added these lines to the end of my .Rprofile:
#testing SO problem with libloading
library(stats)
runif(10)
And the console returns ten nice numbers.