Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the directories for Quarto documents in Rstudio

I am currently trying to transition to Quarto from Rmarkdown. However, I am facing an issue with setting the correct project directory. I wanted to ask if there is something similar to this option in Rmarkdown with Quarto. enter image description here

My understanding is that I need to make a .yml file to specify the directory I want to use, which is not very straightforward for me.

like image 960
Abdullah Abdelaziz Avatar asked Dec 16 '25 13:12

Abdullah Abdelaziz


2 Answers

You may want to use {here} package which is really useful for working with filepaths within projects.

Suppose I have created a quarto project within Rstudio by following File -> New Project -> New Directory -> Quarto Project and made some folders and files within it. Therefore my current project structure looks like

$
│ test_proj.Rproj
│ _quarto.yml
│
├─-data
│    mtcars.csv
│
└─-scripts
     delete.qmd

Now to invoke the mtcars.csv file from delete.qmd you can do the following

---
title: "Test File"
format: html
---

## Quarto

```{r reading-data}

df <- read.csv(here::here("data/mtcars.csv"))
```

As per the documentation of here::here()

it will always locate the files relative to your project root

So thinking in terms of the project root (where the test_proj.Rproj is), you write the path of mtcars.csv in your qmd or R-script files as "data/mtcars.csv" and It doesn't matter where the script files are, since you are invoking the csv files relative to the project root which is fixed within a project.

To know more about {here}, see here

like image 166
Shafee Avatar answered Dec 19 '25 05:12

Shafee


You can add global knitr options in the document yaml:

---
title: "My Document"
format: html
knitr:
  opts_knit:
    root.dir: "c:/my/project/directory"
---
like image 41
Mike O'Brien Avatar answered Dec 19 '25 07:12

Mike O'Brien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!