Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top