0

I have a similar to question to what was posted here, and tried to set up my folders in a similar manner: (Writing an R package vignette that reads in an example file?)

I'm writing a vignette for a package in R.

I made a .Rnw file and put it into a subdirectory inst/doc inside my package pV. Inside the same subdirectory inst/doc, I put a folder example containing a .rda file called tree.rda.

Before I can run any of the functions in the vignette, I have to read in the tree.rda file (this is lines 13-21):

```{r}
library(pV)
library(plyr)
library(reshape2)
library(ggplot2)
library(stringr)
library(igraph)
system.file('tree.rda', 'example', package = 'pV')
load("tree.rda")
```

but get the error:

* checking for file '/Users/MacOwner/Desktop/pV/DESCRIPTION' ... OK
* preparing 'pV':
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ... ERROR
Quitting from lines 13-21 (pV.rmd) 
Error: processing vignette 'pV.rmd' failed with diagnostics:
cannot open the connection
Execution halted
Error: Command failed (1)

How can I successfully read in the .rda file so that my next command could be (and show the first lines of tree.rda file):

```{r}
head(tree)
```

and so that I can use this tree object as input to additional functions that require it as an input in the later parts of the vignette?

Community
  • 1
  • 1
  • In general you should attempt to run the code you post. It's obvious that this code doesn't do what you think it should do and this isn't related to the code being in a vignette. – Dason Apr 25 '14 at 18:27

1 Answers1

3

If I understand your question, you need to either assign the result of system.file or nest the commands. So either:

file <- system.file('tree.rda', 'example', package = 'phyViz')
load(file)

or

load(system.file('tree.rda', 'example', package = 'phyViz'))

should make the data available. Try it on the command line and do ls() afterwards to see if it is there.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
  • It is not there :o(. Typing in ls() shows it is not there. Typing in file shows a blank string –  Apr 25 '14 at 22:11
  • Sorry, off working on a project. Looks like you have worked it out. `R.exts` has all the details of how to construct a package but one has to keep going back to it! But you probably know that! – Bryan Hanson Apr 26 '14 at 01:28