简体   繁体   English

从 GitHub 上的 R package 下载小插图(Rmd)?

[英]Download vignettes (Rmd) from R package on GitHub?

I'm trying to install an R package from a private repository on GitHub .我正在尝试从 GitHub 上的私有存储库安装GitHub Package objects, such as data and functions , are downloaded as they should, but I'm missing the vignettes , ie the .Rmd that is located in the /vignettes folder of the package. Package 对象(例如datafunctions )已按应有的方式下载,但我缺少vignettes ,即位于.Rmd/vignettes文件夹中的 .Rmd。

library(devtools)
devtools::install_github("person_name/repo_name", build_vignettes = TRUE, auth_token =  "xxx")

My goal is to be able to download both functions , data and the .Rmd from the package using install_github() .我的目标是能够使用install_github()从 package 下载functionsdata.Rmd

Ideally, the functions and data from the package would be in the RStudio memory (which works fine), while the .Rmd file should be downloaded locally to the directory I'm in when I download the package. Ideally, the functions and data from the package would be in the RStudio memory (which works fine), while the .Rmd file should be downloaded locally to the directory I'm in when I download the package.

The purpose is to make it easy for a user to re-run the analysis (the .Rmd ) with the included data and functions .目的是使用户可以轻松地使用包含的datafunctions重新运行分析( .Rmd )。

Is this possible or have I misunderstood the function?这是可能的还是我误解了 function?

Vignettes are not stored in the local working directory.小插图不存储在本地工作目录中。 They are stored in the package bundle itself.它们存储在 package 包本身中。 You typically access them using您通常使用

vignette("topicname", package="packagename")

If you want to get the path to that RMD file (assuming the source file is a markdown file which is not the case for all packages), you can write a little helper如果您想获取该 RMD 文件的路径(假设源文件是 markdown 文件,并非所有软件包都如此),您可以编写一个小助手

get_vignette_source_path <- function(...) {
   v <- vignette(...)
   file.path(v$Dir, v$File)
}

For example with the dplyr "colwise" help例如使用dplyr "colwise" 帮助

get_vignette_source_path("colwise", package="dplyr")

You could also have it copy the file to your working directory您也可以让它将文件复制到您的工作目录

file.copy(get_vignette_source_path("colwise", package="dplyr"), ".")

You could include a function in your package to do this if you like.如果您愿意,可以在 package 中包含 function 来执行此操作。 you can also actuyally open an edit window for the source file itself with您还可以实际打开源文件本身的编辑 window

edit(vignette("colwise", package="dplyr"))

and then the user could save that value where they like.然后用户可以将该值保存在他们喜欢的位置。

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

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