When I install the yaml package, an annoying error message pops up in RStudio if it had been previously installed. How can I tell if the package was already installed so I can decide in my code whether to install the package or not?
The message is in a pop up window and it is:
One or more of the packages that will be updated by this installation are currently loaded. Restarting R prior to updating these packages is strongly recommended. RStudio can restart R and then automatically continue the installation after restarting (all work and data will be preserved during the restart). Do you want to restart R prior to installing?
The dpkg-query command can be used to show if a specific package is installed in your system. To do it, run dpkg-query followed by the -l flag and the name of the package you want information about.
packages() Calling installed. packages() returns a detailed data frame about installed packages, not only containing names, but also licences, versions, dependencies and more.
You can either use the dpkg command's log or the apt command's log. You'll have to use grep command to filter the result to list the installed packages only. This will list all the packages including the dependencies that were installed recently on your system along with the time of installation.
This will load yaml
, installing it first if its not already installed:
if (!require(yaml)) {
install.packages("yaml")
library(yaml)
}
or if you want to parameterize it:
pkg <- "yaml"
if (!require(pkg, character.only = TRUE)) {
install.packages(pkg)
if (!require(pkg, character.only = TRUE)) stop("load failure: ", pkg)
}
UPDATE. Parametrization.
you can use installed.packages()
to find installed packages
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