I had the reverse problem from the OP, and I wanted to prevent my custom functions in .Rprofile
from being overridden when I defined a variable with the same name as a function, but I ended up putting my functions to ~/.R.R
and I added these lines to .Rprofile
:
if("myfuns"%in%search())detach("myfuns")
source("~/.R.R",attach(NULL,name="myfuns"))
From the help page of attach
:
One useful ‘trick’ is to use ‘what = NULL’ (or equivalently a
length-zero list) to create a new environment on the search path
into which objects can be assigned by assign or load or
sys.source.
...
## create an environment on the search path and populate it
sys.source("myfuns.R", envir = attach(NULL, name = "myfuns"))