Writing a R vinyl sample that reads in an example file?

I am trying to write a vignette for a package in R. I followed the training course from Vanderbilt University , as well as the official documentation .

I created a .Rnw Sweave file and placed it in the inst/doc subdirectory inside my package. Inside the same inst/doc subdirectory, I put the example folder containing some example text files. My package has the function myparser(path) , which I want to demonstrate in a vignette; myparser(path) creates several frames of data by reading in text files inside a folder with an absolute path name path .

Then I checked the package using R CMD CHECK and got this error:

 * checking running R code from vignettes ... 'mypackage-vignette.Rnw' using 'UTF-8' ... failed ERROR Errors in running code in vignettes: when running code in 'mypackage-vignette.Rnw' ... > library(mypackage) Loading required package: ggplot2 > myparser("/example/") Warning in file(file, "rt") : cannot open file '/example/': No such file or directory When sourcing 'mypackage-vignette.R': Error: cannot open the connection Execution halted 

I see that my attempt to use the relative path to the folder did not work (probably should have been obvious to me), but I'm still not sure how to fix this situation. I do not want to replace path with the absolute path to the folder on my computer, because then the vignette code will not play on other people's computers.

How to include example files in a package so that the vignette code is reproducible? Am I even right about this problem?

(Sorry, this question is no longer reproducible!)

+6
source share
1 answer

You can use system.file('doc', 'example', package = 'mypackage') to link to this directory, because R will install the package before creating the vignette, as you can see when R CMD build mypackage starts R CMD build mypackage .

+9
source

Source: https://habr.com/ru/post/920164/


All Articles