From tobias.verbeke at openanalytics.eu  Sat Oct 31 21:59:48 2015
From: tobias.verbeke at openanalytics.eu (Tobias Verbeke)
Date: Sat, 31 Oct 2015 21:59:48 +0100 (CET)
Subject: [Rd] Example input data with example output using relative
 pathway in vignette of R package?
In-Reply-To: <CAGRPoRSBs2-dc=KhqDrOA4fK8U0oHF89LY2=gF9rPE9shqOYag@mail.gmail.com>
References: <CAGRPoRSBs2-dc=KhqDrOA4fK8U0oHF89LY2=gF9rPE9shqOYag@mail.gmail.com>
Message-ID: <1128761089.6735862.1446325188228.JavaMail.zimbra@openanalytics.eu>

Hi Luck,

If your package is installed, 

system.file("extdata", "InputFiles", package = "myPackage")

will give you the full path of the InputFiles directory.

See ?system.file for more details.

HTH,
Tobias

----- Original Message -----
> From: "Luck Buttered" <luckbuttered at gmail.com>
> To: "r-devel at r-project.org" <r-devel at r-project.org>
> Sent: Saturday, October 31, 2015 9:14:06 PM
> Subject: [Rd] Example input data with example output using relative pathway in vignette of R package?

> I'm putting together an R package. I would like to show example code in the
> vignette, where example data files (included in the package) are used to
> generate an (example) output file.
> 
> I read about using example data in Hadley Wickham's post (
> http://r-pkgs.had.co.nz/data.html), and believe I should keep my example
> data as raw data, as it must be parsed to generate the output.
> 
> So, I created a directory in my package structure
> 
> /Users/userName/myPackage/inst/extdata/
> 
> with subdirectories InputFiles and OutputFiles.
> 
> And I put the example file (exampleData.csv) inside of the InputFiles
> subdirectory (/Users/userName/myPackage/inst/extdata/InputFiles).
> 
> My vignette is located in:
> 
> /Users/userName/myPackage/vignettes/myPackage.Rnw
> 
> It contains the following syntax:
> 
> <<eval=FALSE>>=
> fileString = "/Users/userName/myPackage/inst/extdata/InputFiles/exampleData.csv"
> doFunction1(fileString)
> doFunction2(fileString)
> doFunction3(fileString, output
> ="Users/userName/myPackage/inst/extdata/OutputFiles")@
> 
> I am having two problems with developing this vignette and its example
> datasets:
> 
> 1) I am unsure if my use of the extdata file is appropriate. This seemed to
> be the best directory name and location to place my example files,
> according to the aforementioned Hadley Wickham reference.
> 
> 2) I am unsure how to make the pathways relative, instead of absolute, as I
> have them currently. This example code does not run automatically, as you
> can see. Instead, I have it under an R chunk of eval=FALSE so that it is
> simply listed there for the users to test themselves. After running the
> example code, the users can also check that the output file was indeed
> created in (/Users/userName/myPackage/inst/extdata/OutputFiles). What is
> the best way for me to allow the user to not have to use an absolute path
> when following the example? Is it possible to just follow a relative path
> from within the package directory myPackage? I cannot create a help manual
> (AFAIK) because this example code is not just an example of running one
> function; instead, it is an example of running several functions and then
> viewing the output.
> 
> If it would make more sense for me to just run the R chunk with eval=TRUE,
> I would have the same question: How could I get it to automatically run
> with just relative pathways?
> 
> Thank you for any advice!
> 
>	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Example input data with example output using relative pathway in vignette of R package?
Tobias Verbeke