Unload a package without restarting R

0 votes

I want to unload a package without restarting R

I tried using ?library, but it does not show options that would unload a package.

Then, I tried using detach that can unload a package.
But it failed and shows an error:

detach(vegan)
Error in detach(vegan) : invalid name argument
detach("vegan")
Error in detach("vegan") :invalid name argument

Any suggestions to unload the package?

Apr 17, 2018 in Data Analytics by Sahiti
• 6,370 points
3,601 views

1 answer to this question.

0 votes

Try the below option:

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

NOTE: You can try ?detach for details on detach

Multiple versions of a package can be loaded once.

To guarantee that all copies are detached, use the below function:

detach_package <- function(abcpkg, character.only = FALSE)
{
  if(!character.only)
  {
    abcpkg <- deparse(substitute(abcpkg))
  }
  search_item <- paste("package", abcpkg, sep = ":")
  while(search_item %in% search())
  {
    detach(search_item, unload = TRUE, character.only = TRUE)
  }
}

If you want to use detach for a single package, then, use the below options:

detach_package(vegan)

OR

detach_package("vegan", TRUE)
answered Apr 17, 2018 by DataKing99
• 8,240 points

Related Questions In Data Analytics

+1 vote
1 answer

Unload package without restarting R

You can use the unloadNamespace command, as ...READ MORE

answered Nov 5, 2018 in Data Analytics by Kalgi
• 52,360 points
574 views
0 votes
1 answer

How can I import a file in R without giving the destination/file path to the specified file?

You can use the window explorer to ...READ MORE

answered Aug 28, 2018 in Data Analytics by Abhi
• 3,720 points

edited Aug 28, 2018 by Vardhan 2,460 views
0 votes
1 answer
0 votes
1 answer

How to install an R package from source?

If you have your file located locally ...READ MORE

answered Apr 14, 2018 in Data Analytics by CodingByHeart77
• 3,740 points
613 views
0 votes
1 answer

Is there any way to check for missing packages and install them in R?

There are 2 options: Either you can use ...READ MORE

answered Apr 17, 2018 in Data Analytics by nirvana
• 3,130 points
693 views
0 votes
1 answer

Unable to install the 'devtools' package in R

Run the below command in your Ubuntu/Linux ...READ MORE

answered Jun 6, 2018 in Data Analytics by Bharani
• 4,660 points
1,477 views
0 votes
1 answer

R package dplyr reinstall every instance

In R, there are two steps of ...READ MORE

answered Jun 1, 2022 in Data Science by Sohail
• 3,040 points
448 views
0 votes
1 answer

How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

answered May 17, 2018 in Data Analytics by DataKing99
• 8,240 points
1,633 views
0 votes
1 answer

How to evaluate expression given as a string in R?

The eval() function evaluates an expression, but "5+5" is a string, ...READ MORE

answered Jun 7, 2018 in Data Analytics by DataKing99
• 8,240 points
4,220 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP