0 votes
2 views
in R Programming by (3.5k points)
edited by

How can I unload a package without restarting R?

I tried library but it doesn’t show any options that would unload the package.

I also tried detach but it also failed:

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

So How can I perform this task?

1 Answer

0 votes
by (46.1k points)
edited by

Try this using ?detach:

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

Alternatively you can also use unloadNamespace command

unloadNamespace("ans")

For multiple versions of a package loaded at once use

detach_package <- function(pkg, character.only = FALSE)

{

 if(!character.only)

{

  pkg <- deparse(substitute(pkg))

}

search_item <- paste("package", pkg, sep = ":")

while(search_item %in% search())

 {

   detach(search_item, unload = TRUE, character.only = TRUE)

 }

}

In your case either use

detach_package(ans)

or use

detach_package("ans", TRUE)

Thank you for reading this answer.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...