Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knit error. Object not found

Tags:

r

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:'

enter image description here

like image 602
Jeff Avatar asked Feb 20 '17 09:02

Jeff


People also ask

Why does R keep saying object not found?

This error usually occurs for one of two reasons: Reason 1: You are attempting to reference an object you have not created. Reason 2: You are running a chunk of code where the object has not been defined in that chunk.

Why does my code run but not knit?

If a chunk works in R but not when you knit, it is almost always because you've changed a variable in your global working environment not using code in a chunk. Try restarting your R session and running each chunk sequentially to make sure all your variable values are up to date.

Where is knit option in RStudio?

If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.


2 Answers

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.

like image 184
arunchiri Avatar answered Sep 23 '22 00:09

arunchiri


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.

like image 34
GGamba Avatar answered Sep 24 '22 00:09

GGamba