What I'm trying to do is plain straight forward:
required_pkgs <- c("A", "B", "C")
for (pkg in required_pkgs) {
library(pkg)
}
At runtime, the R interpreter tries to lookup (3 times) a package called "pkg" (and of course it fails at the first try), when I do expect it to be either "A", "B", "C".
Of course My ignorance of the language makes me miss the point, but why it behaves like that? Does R expects me to write the following code:
library(A)
library(B)
library(C)
I do need to iterate over each package loading to handle missing packages and fallback to installing it or pick an alternative.
BASICALLY I was whining for not being able to iterate over the array of packages names and each call to library
with the for
parameter (pkg
) resulted in R trying to load a non-existent pkg
library. This is solved by adding the character.only=TRUE
argument a the invocation of library
.
EDIT: more infos, sorry for being so vague...