I see that I often use the install.package function, especially when I have to check another user's code or run an example.
I am writing a function that installs and downloads a package. I tried the following, but this did not work:
inp <- function(PKG) { install.packages(deparse(substitute(PKG))) library(deparse(substitute(PKG))) }
When I typed inp(data.table) it says
Error in library(deparse(substitute(PKG))) : 'package' must be of length 1
How to pass the library name as an argument in this case? I would appreciate it if someone could also direct me to the information related to passing any object as an argument to a function in R
source share