Having trouble knitting rmd file

I am trying to knit my document to knit, but eerytime i do so i get the error message:
error in as.data.frame(x): object 'ew_sa_data_sample' not found
even though the object does exist bc i have used it without issue until now.

When you knit, R runs in a separate environment. Sometimes this error occurs when the object appears in your regular environment, but isn't defined in the file being knit.

Do you know how I can fix this ?

You have to define it inside the .Rmd file. If you use data from a .csv file, just load it inside your .Rmd file like you would do in a regular R session.

2 Likes

The object has already been read in whcih is why I'm confused that the object isnt found when trying to knit

Is it read in the rmd file? You might want to post your .rmd file up to the point where the error occurs.

1 Like

There is a difference between creating a vector in the interactive session (e.g. in the console) like

my_vec <- c('a','b','c')

and performing operations on them like inside your .Rmd file

to_upper(my_vec)

vs. knitting your .Rmd file. Imagine initializing the vector above in the console and writing to_upper(my_vec) inside your .Rmd file. If you run the chunk by hand everything is fine, since the object is in your currently active environment. But if you knit the file, R will start a fresh environment with no manually defined variables at all. If the chunk to_upper(my_vec) is encountered, there will be an error since the object my_vec has been created by hand in the console, but was not defined in the .Rmd file and hence R will not be able to find it.

If this is indeed not the problem (but it looks like it), please copy your code from the .Rmd file (or at least the relevant part where the error occurs) and let us have a look on it.

Kind regards

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.