1
是否有可能从编译后的R包中找到包到R源代码?我想从CRAN或其他来源安装的软件包中获取各种功能的源代码。我知道我可以通过单独的下载下载完整的源代码。可能反编译R字节码?
是否有可能从编译后的R包中找到包到R源代码?我想从CRAN或其他来源安装的软件包中获取各种功能的源代码。我知道我可以通过单独的下载下载完整的源代码。可能反编译R字节码?
您可以使用args()
和body()
提取包中函数的文本。要列出软件包中的所有对象,可以使用ls()
并指定软件包环境。
警告:下面的方法会给你的源代码,但不是NAMESPACE
或DESCRIPTION
。
例如,要打印所有的源代码ggplot2
,试试这个:
library(ggplot2)
pkg <- as.environment("package:ggplot2")
allfuns <- ls(envir = pkg)
for(f in allfuns[1:2]){
args <- capture.output(print(args(f)))[1]
body <- paste(capture.output(print(body(f))), collapse = "\n")
cat(sprintf("%s <- %s\n%s\n\n", f, args, body))
}
这会给你:
%+% <- function (e1, e2)
{
e2name <- deparse(substitute(e2))
if (is.theme(e1))
add_theme(e1, e2, e2name)
else if (is.ggplot(e1))
add_ggplot(e1, e2, e2name)
}
%+replace% <- function (e1, e2)
{
if (!is.theme(e1) || !is.theme(e2)) {
stop("%+replace% requires two theme objects", call. = FALSE)
}
e1[names(e2)] <- e2
e1
}
是不是操作系统依赖?另外,对我来说,超级用户将是一个更好的网站来问这样的问题 – 2015-11-20 01:01:30
我想在Windows上比在* nix上甚至在OSX上更复杂。 – 2015-11-20 01:06:07
当然不容易。我会好奇的看看是否有人想出答案。 –