简体   繁体   中英

R: Show sources of install.packages

I would like to read the source files of the install.packages function. 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). Do you have any idea how i can access them? BTW I thought hiding source files was something not commonly done in 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.

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:

> 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. You can debug that to see what files it downloads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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