3

I'm trying out Quarto and 'converting' my Rmarkdown file into a quarto document. In my old Rmarkdown file, I would use source("R_datacleaning.R") and source("R_Functions.R") to run the data cleaning and to load some functions. I've also tried source(here("R_Functions.R")) but it doesn't work either. The R-scripts and the qmd files are in the same directory.

I can't seem to get that to work in the .qmd. The error I get is Error: RStudio not running. I've searched around and looked at the Quarto documentation, but couldn't find anything relating to this. I think there might be something I'm not understanding about the Quarto environment in RStudio. Would appreciate any help, thanks!

Edit:

---
title: "quarto_test2"
format: html
---

```{r}
library(here)

source(here("R_Functions.R"))
```

Error message is:

processing file: quarto_test2.qmd
  |..........                                                            |  14%
  ordinary text without R code

  |....................                                                  |  29%
label: unnamed-chunk-1
Quitting from lines 7-10 (quarto_test2.qmd) 
Error: RStudio not running

Execution halted

R_Functions.R is in the same directory as quarto_test2.qmd, as previously mentioned.

Version Info

  • RStudio version is 2022.07.2.
  • R version 4.2.0.
  • Quarto version 1.1.245.
shafee
  • 15,566
  • 3
  • 19
  • 47
A. Piong
  • 192
  • 1
  • 11
  • Please provide a minimal reproducible example that is not working for your case and giving errors. Also include information what `quarto` and Rstudio version you are using. – shafee Oct 26 '22 at 03:22
  • I didn't feel a need to include a reprex as I'm pretty sure this is not an issue with my code, but with the `source()` function not working in .qmd. Could be a directory issue, or something with knitr, that I'm not understanding. Anyway, I will still update the main post with a reprex if you really want one. – A. Piong Oct 26 '22 at 04:18
  • Yes, please do. Its always a better idea to include a reprex, even it seems trivial (Because what may seem trivial to you, may not seem to others). Anyway, I have used `source()` already several times in qmd files and faced no problem so far :) – shafee Oct 26 '22 at 04:22
  • Thanks, I've added the reprex. I see that Quarto was built under R version 4.2.1, but mine is 4.2.0. Not sure if that might be it? Have you used `source()` on .R files? `list.files()` points correctly at my directory and prints `"quarto_test2.qmd"` together with `"R_Functions.R"` Also, the issue/error does not change whether I include `here()` or not. – A. Piong Oct 26 '22 at 04:28
  • Yes. I Have used `source` on R files. By the way, what's the content of your script `R_Functions.R`? – shafee Oct 27 '22 at 10:12

2 Answers2

4

I was successful in pdf with

---
title: "source() external R script in Quarto, in PDF"
format: 
  pdf:
    toc: true # table of contents
---

Some text...

```{r}
#| echo: true
#| eval: false # skip evaluation
#| file: C:/directory/script.R
```

Some text...

2

After much similar frustration I found this: https://github.com/rstudio/rstudio/issues/11361

Essentially add into your setup:

project:
     execute-dir: project