How to unload all packages and load only necessary

I usually have got about 150 packages loaded.
I have used this:

library(nothing, quietly = TRUE)

and then I have only utils and base loaded. This is very good. When I want to load tidyverse or other needed packages I get an error:

Loading the required package: Rcpp
Error: loading package or namespace failed for 'Rcpp' in .Call(C_R_getClassFromCache, name, .classTable):
 NULL value passed as symbol address
ERROR: package 'Rcpp' could not be loaded
ERROR: loading package or namespace failed for 'tidyverse':
 .onAttach failed in 'attachNamespace()' function for 'tidyverse' package, details:
  call: NULL
  error: loading package or namespace failed for 'ggplot2' in .Call(C_R_getClassFromCache, name, .classTable):
 NULL value passed as symbol address

I want to do this because when I use :

m <- brms::brm(NumericLikert ~ 1, data=data1, family=cumulative(link='probit'), cores=4)

and all packages are loaded it stops constantly and asks me about conflicts preferences. This is annoying.
So I thought that unloading all packages and load only a few would be a solution, but it is not.
Any help will be much appreciated.

1st to say is that r library(name of package) will load one library at a time.

2nd to say is that ggplot2 and tidyverse are very useful packages and you should try to uninstall packages and reinstall them. to uninstall a package use the function r remove.packages(“package name”)

I do not want to reinstall any packages, I want to load when necessary.
I use library(tidyverse) and errors come up.

why / how ?
When I start a new session I have 0 packages loaded

for a given project; the packages needed for that project are loaded by the use of a script that lists them out.

I wonder if you are not using project(s) ? and you potentially save/load a single workspace to do all manner of work ? I advise against such an approach.

When I unload everything I only have got base and utils. My question is why do errors come up when I try to load my necessary packages ?

how are you supposing to unload things ? and have you verified that you only have base and utils ?

Your first code snippet seems to be a simple error ?

# Error in library(nothing, quietly = TRUE) : 
#   there is no package called ‘nothing’

what should happen here ?


Yes, I have:


I wouldnt rely on that functionality.
My advice is to find alternative solutions that dont involve attempting to 'unload' libraries; R doesnt seem to have been designed with this in mind; so you will get frustrated at every turn.

You could look at package conflicted to explicitly deal with potential conflicts in your projects in an upfront manner.

if brms::brm is simply wildly misbehaving then I would raise an issue with its developers.

Perhaps the solution is to load your environment cleanly when you start. If you have the following option not selected as in the image below (from Tools.. Global Options.. in RStudio:

This will ensure that you have nothing else loaded except the basic tools you need. It might avoid the problems you have been having.

Just a thought. I hope it helps.

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.