Rmarkdown doesn’t knit with data listed in the environment

Greetings,

This is my first time trying to use knit in an Rmd file.
The last command chunk works just fine when I run the chunk from the file but not when I try to knit.

---
title: "Printout"
author: "Jason"
date: "4/20/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r ---> Libraries}
library(tidyverse)
library(reprex)
library(here)
here()
dr_here(show_reason = FALSE)
```
```{r}
colnames(dat.SM)
```

The R markdown tab:

==> rmarkdown::render('/Users/jcraggs/Documents/GitHub/Brad_PT/Brad_printout.Rmd',  encoding = 'UTF-8');


processing file: Brad_printout.Rmd
  |..........                                                            |  14%
  ordinary text without R code

  |....................                                                  |  29%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |..............................                                        |  43%
  ordinary text without R code

  |........................................                              |  57%
label: ---> Libraries
  |..................................................                    |  71%
  ordinary text without R code

  |............................................................          |  86%
label: unnamed-chunk-1

Quitting from lines 25-27 (Brad_printout.Rmd) 
Error in is.data.frame(x) : object 'dat.SM' not found
Calls: <Anonymous> ... withVisible -> eval -> eval -> colnames -> is.data.frame
Execution halted

Does any one have any suggestions?

Jason the #rstatsnewbie

Hey there,

I see that you're already using the here package which is great! It looks as if it is not able to find your dat.SM file. You will need to "read" it in first within that chunk before you are able to run something like colnames over the object. You can get the whole path to that file via here::here(dat.SM) which will also tell your Rmarkdown script from where to get the file (if it is within your .RMD project folder).

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

Thanks @GreyMerchants for the response. However, I'm still wondering why I can run the code chunk without issue from within the file? Any ideas?