8

I'm trying to use data from Global Environment in R Markdown. When I call a 'summary(mydata)' it gives me this error:

object 'mydata' not found

I got all my work in many different scripts, so that is not easy for me to create a .R file for each result.

So, can I call data defined on Global Environment in R Markdown?

Thank You.

Suat Atan PhD
  • 1,152
  • 13
  • 27
DarkSide
  • 157
  • 2
  • 2
  • 6

1 Answers1

19

There are 2 ways to load the data myData to your .RMD file:

  1. Don't knit your file with the Rstudio "knit" button:

    library(knitr)
    knit('your_file.Rmd')
    

This will take your recent environment into account and the error should be gone.

  1. Store your myData as "myData.RData" and load it manually in your RMD file

    ```{r load myData, include=FALSE}
    load("myData.RData")
    

    If you do it this way you can use the "knit" button from RStudio.

I hope one of this ways is a good solution for you.

Heikki
  • 2,214
  • 19
  • 34
J_F
  • 9,956
  • 2
  • 31
  • 55
  • This does not work; I'm getting the error: "cannot open compressed file 'DATASET NAME.Rdata', probable reason 'No such file or directory'Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection" – Barry DeCicco Apr 22 '21 at 21:20