如何从 DESCRIPTION
文件中读取 Authors@R
字段作为向量?
> packageDescription("dplyr")$`Authors@R`
[1] "\n c(person(given = \"Hadley\",\n family = \"Wickham\",\n role = c(\"aut\", \"cre\"),\n email = \"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e161f1a121b073e0c0d0a0b1a1711501d1113" rel="noreferrer noopener nofollow">[email protected]</a>\",\n comment = c(ORCID = \"0000-0003-4757-117X\")),\n person(given = \"Romain\",\n family = \"François\",\n role = \"aut\",\n comment = c(ORCID = \"0000-0002-2444-4226\")),\n person(given = \"Lionel\",\n family = \"Henry\",\n role = \"aut\"),\n person(given = \"Kirill\",\n family = \"Müller\",\n role = \"aut\",\n comment = c(ORCID = \"0000-0002-1416-3412\")),\n person(given = \"RStudio\",\n role = c(\"cph\", \"fnd\")))"
最佳答案
我们可以用eval(parse
)包装,因为它返回一个字符串
eval(parse(text = packageDescription("dplyr")$`Authors@R`))
即如果我们检查 cat
cat(packageDescription("dplyr")$`Authors@R`)
c(person(given = "Hadley",
family = "Wickham",
role = c("aut", "cre"),
email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="315950555d5448714342454455585e1f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>",
comment = c(ORCID = "0000-0003-4757-117X")),
person(given = "Romain",
family = "François",
role = "aut",
comment = c(ORCID = "0000-0002-2444-4226")),
person(given = "Lionel",
family = "Henry",
role = "aut"),
person(given = "Kirill",
family = "Müller",
role = "aut",
comment = c(ORCID = "0000-0002-1416-3412")),
person(given = "RStudio",
role = c("cph", "fnd")))
关于从 R 包描述中读取 Authors@R 字段作为向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69667175/