Reputation: 8411
I have an uncleaned dataset. So, I have imported it to my R studio.Then when I run nrow(adult)
in the rmarkdown file and press ctrl+Enter
it works, but when i press the knit
the following error appears:'
Upvotes: 15
Views: 71650
Reputation: 43
I am rendering in word. Here's what finally got my data loaded from the default document directory. I put this in the first line of my first chunk.
load("~/filename.RData")
Upvotes: 0
Reputation: 41
If you have added eval = FALSE
the earlier R code won't execute in which you have created your object.
So when you again use that object in a different chunk it will fail with object not found message.
Upvotes: 4
Reputation: 103
Another option, in the same way as the previous, but really useful in case you have a lot of diferent data
Once you have all your data generated from your R scripts, write in your "normal code" ( any of your R scripts):
save.image (file = "my_work_space.RData")
And then, in your R-Markdown script, load the image of the data saved previously and the libraries you need.
```{r , include=FALSE}
load("my_work_space.RData")
library (tidyverse)
library (skimr)
library(incidence)
```
NOTE: Make sure to save your data after any modification and before running knitr.
Upvotes: 6
Reputation: 783
When knitting to PDF
```{r setup}
knitr::opts_chunk$set(cache =TRUE)
```
Worked fine.
But not when knitting to Word.
Upvotes: 0
Reputation: 321
Because usually I've a lot of code that prepares the data variables effectively used in the knitr documents my workaround use two steps:
Is no so elegant but is the only one that I've found.
I've also tried to access to the global environment variables using the statement get() but without success
Upvotes: 4
Reputation: 13680
When you knit
something it gets executed in a new environment.
The object adult
is in your environment at the moment, but not in the new one knit creates.
You probably did not include the code to read or load adult
in the knit.
If you clear your workspace, as per @sebastian-c comment, you will see that even ctrl+enter
does not work.
You have to create the adult
object inside your knit
. For example, if your data in from a csv add
adult <- read.csv2('Path/to/file')
in the first chunk.
Hope this is clear enough.
Upvotes: 17