简体   繁体   English

R:显示 install.packages 的来源

[英]R: Show sources of install.packages

I would like to read the source files of the install.packages function.我想阅读install.packages函数的源文件。 More specifically, I'd like to understand exactly how this function downloads files from web repositories.更具体地说,我想确切地了解此功能如何从网络存储库下载文件。

However, these source files seem hidden ( debug(install.packages) is useless).但是,这些源文件似乎是隐藏的( debug(install.packages)没用)。 Do you have any idea how i can access them?你知道我如何访问它们吗? BTW I thought hiding source files was something not commonly done in R...顺便说一句,我认为隐藏源文件在 R 中并不常见......

If you are running in RStudio, there are two functions with that name: the wrapper that RStudio put in place, and the original one from the utils package in base R.如果您在 RStudio 中运行,则有两个具有该名称的函数:RStudio 放置的包装器,以及基础 R 中utils包中的原始函数。

You can see the original one by typing你可以通过输入看到原始的

utils::install.packages

The source is really long, so I won't post it.源码很长,就不贴了。

You can see the RStudio replacement by leaving off the prefix:您可以通过省略前缀来查看 RStudio 替换:

> install.packages
function (...) 
.rs.callAs(name, hook, original, ...)
<environment: 0x7f856709ec00>

Seeing what they put in their hook is a little trickier:看到他们在钩子里放的东西有点棘手:

get("hook", envir = environment(install.packages))

It's not completely clear what you want to find from the source, but at some level R is going to use the download.file() function to download things.您想从源代码中找到什么并不完全清楚,但在某种程度上,R 将使用download.file()函数来下载内容。 You can debug that to see what files it downloads.您可以调试它以查看它下载的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM