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:'
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.
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.
If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With