Replies: 9 comments 20 replies
-
|
You are talking about the R package but the R package is a wrapper around the real tool which is not an R package contrary to knitr or RMarkdown (so it is not loaded in R session, does not use your R session or anything from it)
Quarto's document reproducibility is ensured by the fact that by the document itself or the Quarto project. For short, if you wanted to load R packages, render a Quarto document using the loaded functions, this can't be achieved. |
Beta Was this translation helpful? Give feedback.
-
|
ok thanks looks to me like a loss of feature compared to rmarkdown or knitr is there any plan for a knit2pdf that would compile from typst instead of Latex ? this would be great, and keep the facility to pick current R session as in regular knitr/rmarkdown |
Beta Was this translation helpful? Give feedback.
-
|
the workflow is the following quarto is oversized for that simple usage my workflow is more programmatic I would say, don't need the visual cells and don't use jupyter like approaches as they tend in my opinion to get in the way I don't aim at reproducibility with sharing to others with uploading in a cloud, I just need reproducibility for my own scripts of course currently you get typst with R sweave easely only in quarto, there is not knit2dpf using typst instead of latex... I know it's theoretically possible and relatively easy to tweak to do it with knitr, but I did'nt get to it yet when you put everything in a quarto cell you lose reusability of the scripts for other purpose, the scripts is trapped in the quarto document, ok for reproducibility, but not for reusablity of building block R scripts in my opinion there should be only minimal R instruction in a Rnw or quarto template, just the necessary to print the tables and the graphs namely, but not anything heavy to compute, and the rest is just writing thanks |
Beta Was this translation helpful? Give feedback.
-
|
Thanks a lot for your feedback @blset ! Really appreciated to know more about users' workflow and how they try to use Quarto
As a developer of knitr and maintainer of R Markdown, I'll take the opportunity to comment on the workflow and compare it with Quarto. The workflow you have is very different from what Quarto offers. Quarto is closer to how the R Markdown workflow works. A document (respectively .qmd or .Rmd) is expected to contain all computations in cells. They are assumed to be reproducible source files. When preparations are in a bunch of R scripts, they can be loaded for the document in a cell at the top. There are features to easily load them:
So, regarding your comment
They are not trapped. You can do all your code content in an R script and then source it as a script to make computation available for knitr. To share experience, some even structure their work as an R package for their preparation function and data and load the package inside the document to make everything available easily, and have the package available for easy reusability outside the document. The document can then be rendered in a background session without problem. The assumption of having a Rmd file be reproducible by containing everything is the default, and it is even bigger with Quarto as rendering a .qmd will always run in a new clean R session. So, what to do when pre-calculation is needed, when data needs to be shared, or pre-computed ? So in a nutshell, yes, using Quarto will require a change in your workflow. It would have been the same if you were using R Markdown, probably. By using
I understand you are only considering Quarto for Typst support. So thank you for opening This is probably to be considered—PR is welcome there, too. We'll discuss it in the issue in the knitr repo.
For this part, I did not completely follow. To have a BTW, Quarto has support for So |
Beta Was this translation helpful? Give feedback.
-
|
I second the sentiment about this feeling like a major feature loss when coming from |
Beta Was this translation helpful? Give feedback.
-
|
I agree this feels like a loss in functionality. My common pattern is to query/clean data for the whole country, and then use a loop to create HTML outputs for each region from the same Rmd. It's more efficient to do my data preparation in one go, and I'll realise sooner if there are any errors. It seems that a pattern like this isn't possible with Quarto, without extra complications like saving data to disk etc. If Quarto just isn't designed for that, so be it I guess. I can keep using R Markdown. But it seems like a shame, if Quarto is the format that will be more actively developed. |
Beta Was this translation helpful? Give feedback.
-
|
Quarto can use other than Python, but in real work you are not going to use python in one cell and R in another or something like that I ended up using neither quarto nor Rmardown but generate all images in svg and typst modules as text files containing several related tables all from regular R scripts and then I just compose the typst document with vscode using typst directly. There is a instant preview it's blazingly fast, faster than RMardown, zero complications |
Beta Was this translation helpful? Give feedback.
-
|
For raw typst it is better in vscode, once all resources are generated |
Beta Was this translation helpful? Give feedback.
-
|
There has been a lot of discussion on this topic and some are starting to get a bit circular. I will share two save/load options I have used to possibly help fellow R users that have to use Quarto for one reason or another; maybe they are forced to, maybe they simply don't want to use the Rmarkdown styling (default is still BS3?). Both options could be improved if the quarto Method 1: Temporary save and load by nameIn a # Function to save objects to a tempdir as qs2 object and return all the paths
auto_save_by_name <- function(...) {
tmp_dir <- tempdir()
en_obj <- rlang::enquos(...)
en_names <- purrr::map_chr(en_obj, rlang::as_label)
loc_paths <- purrr::map(en_names, \(x) file.path(tmp_dir, paste0(x, '.qs2')))
names(loc_paths) <- en_names
purrr::walk2(list(...), loc_paths, \(x, y) qs2::qs_save(x, y))
loc_paths
}
# List your objects needed for Quarto and pass thru function
list_data_loc <- auto_save_by_name(myfavdata1, myfavdata2, myfavvector1)
# Execute the Quarto param with the data locs
quarto::quarto_render(
input = "./path/to/my.qmd",
execute_params = list(data_loc = list_data_loc)
)
Now, in the QMD file, you can restore all these files at once... # Recalls obj from R tempdir, so dont need to reformat on load
loadlist <- purrr::map(params$data_loc, \(x) qs2::qs_read(x))
setNames(loadlist, names(params$data_loc))
list2env(loadlist, envir = knitr::knit_global());
rm(loadlist);Method 2: Stow/RetrieveTaking this one step further, we can formalize the save and loading procedures with the addition of classes, making them easier to discover within a workflow and pass to another session. This is what I call {targets}-lite, to myself usually. One thing I'm not sure about in the Quarto case, is if the object can be passed as an execution parameter, if not, the path itself could still be sent along (making this a similar method to (1)). Again, this is something I hope Quarto as a package will be able to support, the parameter inputs are not flexible in my experience. There are two paired functions, Similar to (1), you # Example data
temp_data <- data.frame(col1 = rpois(100, 1), col2 = runif(100))
tmp_dir <- tempdir()
temp_data_stowed <- stow(object = temp_data, path = tmp_dir, method = 'fst')
temp_data_stowed2 <- stow(object = temp_data, path = tmp_dir, method = 'fst')You can list all the objects stowed and, as before, pass this to the render call all_stowaways <- lapply(ls()[sapply(ls(), \(x) inherits(get(x), 'stow_temp'))], get)
quarto::quarto_render(
input = "./path/to/my.qmd",
execute_params = list(data_loc = all_stowaways)
)Then in the QMD, you can use purrr::walk(params$data_loc, \(x) retrieve(x, keep_name = TRUE)) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
hello
using knit2pdf at the end of an R script the Rnw templates with latex inherit current session with all libraries loaded
I cannot translate that workflow with quarto
using quarto_render at the end of an R script the qmd files have no access to the current session
I would have to pass individually all objects and load all libraries and source scripts from inside the qmd files
this is very inconvenient
how would you pass the whole session to quarto simply ?
I'm aware the render button in rstudio executes everything in a brand new environment for reproducibility
but I thought using quarto_render would allow the use case of inheriting the current session which is very convenient when sharing is not the goal or to experiment easely
Beta Was this translation helpful? Give feedback.
All reactions