7

I have a package which contains a csv file which I put in inst/extdata per R-exts. This file is needed for the vignette. If I Sweave the vignette directly, all works well. When I run R --vanilla CMD check however, the check process can't find the file. I know it has been moved into an .Rcheck directory during checking and this is probably part of the problem. But I don't know how to set it up so both direct Sweave and vignette building/checking works.

The vignette contains a line like this:

EC1 <- dot2HPD(file = "../inst/extdata/E_coli/ecoli.dot",
node.inst = "../inst/extdata/E_coli/NodeInst.csv",

and the function dot2HPD accesses the file via:

    ni <- read.csv(node.inst)

Here's the error message:

    > tab <- read.csv("../inst/extdata/E_coli/NodeInst.csv")
Warning in file(file, "rt") :
  cannot open file '../inst/extdata/E_coli/NodeInst.csv': No such file or directory

  When sourcing ‘HiveR.R’:
Error: cannot open the connection
Execution halted

By the way, this is related to this question but that info seems outdated and doesn't quite cover this territory.

I'm on a Mac.

Community
  • 1
  • 1
Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78

1 Answers1

8

Have you tried using system.file instead of hardcoded relative paths?

EC1 <- dot2HPD(file = system.file("inst", "extdata", "E_coli", "ecoli.dot", package = "your_package+name"))
node.inst <- system.file("inst", "extdata", "E_coli", "NodeInst.csv", package = "your_package_name")
Max Gasner
  • 1,191
  • 1
  • 12
  • 18
  • Thanks Max. I tried it, but it returns an empty string. Looking at ?system.file, there is the implication that the package must already be installed (because there is a lib.loc argument). Perhaps what is needed is the idea of system.file but evaluated in the checking environment. – Bryan Hanson Nov 14 '11 at 23:33
  • 8
    omit `inst`; that directory is removed during installation -- `system.file("extdata", "E_coli", "ecoli.dot", package="your_package+name")` – Martin Morgan Nov 14 '11 at 23:59
  • I see another problem. The file of interest is in BAH/packages/HiveR/inst/extdata/E_coli/ However, during check the "inst" folder disappears, and instead the path to the file of interest is now: BAHpackages/HiveR.Rcheck/HiveR/extdata/E_coli/NodeInst.csv – Bryan Hanson Nov 15 '11 at 00:01
  • @MartinMorgan Thanks Martin. Your approach works for building and checking the package, but does not work on a direct Sweave. However, I can live with that! – Bryan Hanson Nov 15 '11 at 00:21