R function to return the license of a package?

半世苍凉 提交于 2019-12-08 15:13:38

问题


I'd like to return the package license as declared in the DESCRIPTION file of an R package (ideally I'd rather have the URL that CRAN automatically adds to all the common licenses it recognizes).

I realize I can get the license R itself is distributed under with

license()

which amazingly doesn't apply to packages; e.g. license("packagename")

Nor is this data returned by a call to citation("packagename").


回答1:


you are looking for packageDescription

eg:

packageDescription("stats", fields="License")
[1] "Part of R 2.15.3"

packageDescription("ggplot2", fields="License")
[1] "GPL-2"



回答2:


If you want to get the licenses for all installed packages, then use the installed.packages command.

Borrowing from the help page for this command:

lisc <- installed.packages(fields = "License")

To output the licenses to a csv file:

write.csv(lisc[,c(1,10)], "RPackageLicenses.csv")


来源:https://stackoverflow.com/questions/17508822/r-function-to-return-the-license-of-a-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!