Render issue 2021.09.0 Build 351

Goal: knit an .rmd file file that is save in a directory other than the console directory.
Issue: the knitting machinary seems to have trouble seeing the global environment.

Code chunk:

getwd()
stem(dend$branches)
stripchart(dend$branches)

dend us a 1 column dataframe that was read in using the File | import command. It shows up in the environment tab. Running the code chunk successfully produces both graphs

From the console:
getwd()
[1] "/Users/Rob"

Within the code chunk the path refers to .rmd location:
[1] "/Users/Rob/Documents/Biostats/Week01"

Knit directory is set to Document Directory

When I knit the document I get the following error:
[image]

[1] "/Users/Rob/Documents/Biostats/Week01" The decimal point is 1 digit(s) to the right of the | 2 | 011334 2 | 677788999 3 | 0001334 3 | 55577 4 | 013 4 | 89 5 | 114 5 | 7

R Console

[1] "/Users/Rob/Documents/Biostats/Week01" The decimal point is 1 digit(s) to the right of the | 2 | 011334 2 | 677788999 3 | 0001334 3 | 55577 4 | 013 4 | 89 5 | 114 5 | 7

R 4.1.1

ยท

~/

[image]

Console

Render [image]

Jobs [image]

[image] .../Week01/Baer_HomewordWeek01.Rmd Output Issues

|.............. | 20% ordinary text without R code |............................ | 40% label: unnamed-chunk-1

processing file: Baer_HomewordWeek01.Rmd
Quitting from lines 10-13 (Baer_HomewordWeek01.Rmd)
Error in stem(dend$branches) : object 'dend' not found
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> stem Execution halted

What is this telling me when dend is clearly defined in my global environment? How should I avoid such problems? Is this a bug?

When you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so you need to include in your Rmd file the necessary code to load your data into that separate working environment.

Thank you @andresrcs. I usually use Rscript files rather than notebooks in "real life" so it seemed unusual not to have the global environment available, but if that is the way it is, so be it.

I was trying to have my students use notebooks for homework problems, and in this context reading the book datasets in from the menu seemed to make sense since reproducible data analysis is beyond my teaching target for now.

Maybe I should bring "reproducible data analysis" concepts into scope :slight_smile:

It is available as long as you are working with it interactively, but knitting is a different story, think about this. If you were executing your Rscript non interactively from a terminal or a schedule job you wouldn't have access to data loaded interactively either so it is kind of the same thing.