-1

I am trying to pass a variable to install.package,library, ls and ? Passing a variable to install.package works fine, but I get an error for the others.

name1 <- as.character("dplyr")
install.packages(name1)
library(name1)
ls(name1)
?name1 

I would be greatfull for your help.

adam.888
  • 7,686
  • 17
  • 70
  • 105

1 Answers1

3

One of the three issues, library(name1), can be resolved with the option character.only = TRUE:

library(name1, character.only = TRUE)

To list all the objects in the library with the name stored in name1, try

ls(paste0("package:",name1))

or

ls(getNamespace(name1))

(see here for a discussion on the difference between these two commands, including further options to show hidden objects).

Concerning the third point, ?, I have no solution to offer other than using help(name1) instead, as suggested also by @PierreLafortune.

Community
  • 1
  • 1
RHertel
  • 23,412
  • 5
  • 38
  • 64
  • 2
    If they have a special fetish for question marks you can also use `'?'(name1) ` – Pierre L Feb 20 '16 at 11:16
  • I can't get ls(eval(name1)) to list all the functions in the package. – adam.888 Feb 20 '16 at 13:42
  • 1
    @adam.888 I don't think that you would obtain the desired result if you typed in the name of the package directly, instead of using the variable `name1`. I edited the answer to show a possibility to list all the objects in the package. Hope this helps. – RHertel Feb 20 '16 at 14:47