Sometimes on Stack Overflow, there's a question relative to a package which is not installed on my system, and which I don't plan to reuse later.
If I install the package with install.packages()
, it will be put in one of my R install libraries, and then will take some storage space and be updated each time I run update.packages()
.
Is there a way to install a package only for the current R session ?
You only need to install packages the first time you use R (or after updating to a new version). **R Tip:** You can just type this into the command line of R to install each package. Once a package is installed, you don't have to install it again while using the version of R!
packages()[, "Package"]) { stop("Package Deriv not installed successfully.") }
It shouldn't be an issue unless you install a package as an admin user, and again as a normal user. Then you will have a version in two different locations on your system. That could lead to issues when upgrading, or confusion as to which version is loaded.
You can install a package temporarily with the following function :
tmp.install.packages <- function(pack, dependencies=TRUE, ...) { path <- tempdir() ## Add 'path' to .libPaths, and be sure that it is not ## at the first position, otherwise any other package during ## this session would be installed into 'path' firstpath <- .libPaths()[1] .libPaths(c(firstpath, path)) install.packages(pack, dependencies=dependencies, lib=path, ...) }
Which you can use simply this way :
tmp.install.packages("pkgname")
The package is installed in a temporary directory, and its files should be deleted at next system restart (at least on linux systems).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With