rpackageloadingdefaults

Make package in R not required to load when I startup R/RStudio?


I have looked extensively to find the answer to this before asking and could not find the answer, but if its out there please point me to it. Every time I start R studio I have packages that load automatically like:

Loading required package: RMySQL
Loading required package: DBI
Loading required package: cocor
Loading required package: RMySQL

I would like these packages to stop loading automatically every time I start R studio, and have tried uninstalling and reinstalling R and R studio in addition to the following:

detach("package:RMySQL",unload=TRUE)

For all three of these packages and it doesn't work. Please help! Thank you.

sapply(ls(), function(x) class(get(x)))
named list()

Solution

  • From the comments you've posted, it looks like you're running Windows. The location for a user .RProfile can be shown using:

    (my_rprofile <- file.path(Sys.getenv("R_USER"), ".RProfile"))
    

    You can then check whether that file exists using:

    file.exists(my_rprofile)
    

    and if this returns TRUE, open it for editing using:

    file.edit(my_rprofile)
    

    If the file isn't there, try:

    file.exists(".RProfile")
    

    and if TRUE:

    file.edit(".RProfile")
    

    If you execute this command within RStudio, you should get a window open with the current contents of your .RProfile. I suspect it includes something along the lines of:

    library("RMySQL")
    

    which you then need to remove as appropriate before saving.

    Other things to check:

    Sys.getenv("R_DEFAULT_PACKAGES")
    # should be blank
    .First
    # should give an error that .First not found
    

    If .First is set and you don't have a .RProfile file, you might have it defined in file.path(Sys.getenv("R_USER"), ".RData") and it would be worth renaming that file (or disabling restoring .RData in the RStudio options.

    Even if .First is undefined, I'd still try loading R/RStudio without restoring from .RData since it may be that you're restoring some S4 objects which depend on those packages.