Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy .rmd file included in a Rstudio addin package to a user defined directory

I have a rstudio addin package located here.

One of the addins allows the user to define a directory and it will copy a file that is located in the package to that directory.

the file is located:

atProjectManageAddins/inst/Docs/RMarkdownSkeleton.Rmd

And I am trying to copy it to the user defined directory with something like this:

 file.copy("inst/Docs/RMarkdownSkeleton.Rmd", 
           paste0(Dir, FolderName, "/Reports/", FolderName, "_report.Rmd"))

Where I am trying to copy it from where it is in the package, to where the user defines it to be (Based on two separate arguments Dir and FolderName).

But this doesn't seem to work. My assumption is that I am not referring to the package directory in the correct way. I've tried ./Inst/, ~/Inst/ and maybe a couple more. My assumption now is that there is a more systematic reason for my inability to get file.copy() to work.

Any suggestions? Is this even possible?

Note that if I run the function locally via source() and runGadget(), it works just fine. Only when the package is installed and I use the RStudio addins GUI where it references the intalled package, does it fail. Thus, I'm quite certain I am not correctly defining the file path for the installed .Rmd files.

Edit: I've changed to the following, based on Carl's suggestion (as can be seen on github), but the files are still not being copied over.

file.copy(system.file("Docs","Rmarkdownskeleton.rmd",package="atProjectManageAd‌​dins"),
 paste0(Dir, FolderName, "/Reports/", FolderName, "_report.Rmd"))
like image 781
Andrew Taylor Avatar asked Jul 28 '16 16:07

Andrew Taylor


1 Answers

system.file is the best function for getting a file from a package. I believe this should work for you:

file.copy(system.file("Docs","Rmarkdownskeleton.rmd",package="atProjectManageAd‌​dins"),
paste0(Dir, FolderName, "/Reports/", FolderName, "_report.Rmd"))
like image 161
Carl Avatar answered Nov 17 '22 03:11

Carl