How can library() accept both quoted and unquoted strings

后端 未结 2 1244
自闭症患者
自闭症患者 2020-12-16 00:21

For example, in an R session, typing library(ggplot2) and library(\"ggplot2\") can both import the library ggplot2. However, if I type ggplot2 in t

2条回答
  •  别那么骄傲
    2020-12-16 01:19

    This is how (from the source of library(), which is....long):

    package <- as.character(substitute(package))
    

    A simple way to test this yourself:

    foo <- function(x) as.character(substitute(x))
    > foo(a)
    [1] "a"
    > foo("b")
    [1] "b"
    

提交回复
热议问题