Michael Friendly
2011-Mar-23 14:03 UTC
[Rd] system.file() to read a text file from a vignette
[Env: R 2.12.2, WinXp] In a vignette for the vcdExtra package, I had a text file, tv.dat under data/, that I used in the vignette as <<tv1,results=verbatim>>tv.data<-read.table(system.file("data","tv.dat",package="vcdExtra")) head(tv.data,5) @ I was told that this now generates a warning for non-Rdata files in R CMD check. But I'm now confused about where to put this and how to use system.file() in the vignette to read it. The R-exts.pdf says The R working directory for all vignette tests in R CMD check is the installed version of the ?doc? subdirectory. Make sure all files needed by the vignette (data sets, . . . ) are accessible by either placing them in the ?inst/doc? hierarchy of the source package, or using calls to system.file(). So, I moved this file to inst/doc/extdata/tv.dat, and changed the vignette to <<tv1,results=verbatim>>tv.data<-read.table(system.file("inst","doc","extdata","tv.dat",package="vcdExtra")) head(tv.data,5) @ But I get the error: Error: processing vignette 'vcd-tutorial.Rnw' failed with diagnostics: chunk 23 (label=tv1) Error in read.table(system.file("inst", "doc", "extdata", "tv.dat", package = "vcdExtra")) : no lines available in input How can I fix this? -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
Tobias Verbeke
2011-Mar-23 14:20 UTC
[Rd] system.file() to read a text file from a vignette
Hi Michael, On 03/23/2011 03:03 PM, Michael Friendly wrote:> [Env: R 2.12.2, WinXp] > > In a vignette for the vcdExtra package, I had a text file, tv.dat under > data/, that I used in the vignette as > > <<tv1,results=verbatim>>> tv.data<-read.table(system.file("data","tv.dat",package="vcdExtra")) > head(tv.data,5) > @ > > I was told that this now generates a warning for non-Rdata files in R > CMD check. But I'm now confused about > where to put this and how to use system.file() in the vignette to read > it. The R-exts.pdf says > > The R working directory for all vignette tests in R CMD > check is the installed version of the ?doc? subdirectory. Make sure all > files needed by the vignette > (data sets, . . . ) are accessible by either placing them in the > ?inst/doc? hierarchy of the source > package, or using calls to system.file(). > > So, I moved this file to inst/doc/extdata/tv.dat, and changed the > vignette to > > <<tv1,results=verbatim>>> tv.data<-read.table(system.file("inst","doc","extdata","tv.dat",package="vcdExtra")) > > head(tv.data,5) > @ > > But I get the error: > Error: processing vignette 'vcd-tutorial.Rnw' failed with diagnostics: > chunk 23 (label=tv1) > Error in read.table(system.file("inst", "doc", "extdata", "tv.dat", > package = "vcdExtra")) : > no lines available in input > > How can I fix this?The inst/ will be removed once the package is installed, so you would need system.file("doc", "extdata", "tv.dat", package = "vcdExtra") The warning on non Rdata files is probably due to the fact that .dat is not supported, see Section 1.1.5 of Writing R Extensions and ?data Best, Tobias
Duncan Murdoch
2011-Mar-23 14:21 UTC
[Rd] system.file() to read a text file from a vignette
On 23/03/2011 10:03 AM, Michael Friendly wrote:> [Env: R 2.12.2, WinXp] > > In a vignette for the vcdExtra package, I had a text file, tv.dat under > data/, that I used in the vignette as > > <<tv1,results=verbatim>>> tv.data<-read.table(system.file("data","tv.dat",package="vcdExtra")) > head(tv.data,5) > @ > > I was told that this now generates a warning for non-Rdata files in R > CMD check. But I'm now confused about > where to put this and how to use system.file() in the vignette to read > it. The R-exts.pdf says > > The R working directory for all vignette tests in R CMD > check is the installed version of the ?doc? subdirectory. Make sure all > files needed by the vignette > (data sets, . . . ) are accessible by either placing them in the > ?inst/doc? hierarchy of the source > package, or using calls to system.file(). > > So, I moved this file to inst/doc/extdata/tv.dat, and changed the > vignette to > > <<tv1,results=verbatim>>> tv.data<-read.table(system.file("inst","doc","extdata","tv.dat",package="vcdExtra")) > head(tv.data,5) > @ > > But I get the error: > Error: processing vignette 'vcd-tutorial.Rnw' failed with diagnostics: > chunk 23 (label=tv1) > Error in read.table(system.file("inst", "doc", "extdata", "tv.dat", > package = "vcdExtra")) : > no lines available in input > > How can I fix this?Everything in the "inst" directory is moved up a level when it is installed. So you shouldn't mention "inst" in its path. Duncan Murdoch