How do I get data from an R package to a Quarto document?


I'd like to have my package export data into a Quarto document to be opened and edited by the user. Here's an example of the code for the function in /R, for a package called Demo:

#' DemoQuarto
#' @return text123
#' @export text123

hello <- function() {
  text123 <- print("Hello, world!")

  template = "QuartoDemo.qmd",
  save_as = "example.docx",
  data = list(Package = "Demo"),
  package = "Demo"

I added a folder called templates, and there is a Quarto document inside the templates folder. It's named QuartoDemo.qmd.

The Quarto document has one code chuck (just to see if this works):


However,, when I use devtools::check() to see if this works, I get an error message:

! object 'QuartoDemo.qmd' not found

That's very odd to me, because the QuartoDemo.qmd file is in the templates folder.

How do I get the data from the results of the function to a Quarto document for the user to edit?

Where is your working directory set and does the folder actually have a QuartoDemo.qmd file in it?
To set a working directory use setwd() function.

How to you plan to do that exactly ? Is the user calling a function to copy the .qmd ?

Currently with what you shared, it seems that you are using use_template() in a R file in your package. This means the code will be run at build time and not by the user. A package should be a set of function if you want the user to call it.

Anyhow, I don't think we have enough to help you. You could share your demo project as a github repo so that community can help you with it to understand what is right or wrong.


Thank you for the reply. A minimal example R package has been uploaded to Github, the URL is:

Is there a way at the end of the R code for the template to automatically open up in RStudio so the user can edit it? Right now the template does not open in any way.

I'm pretty sure I can get the data from the R code in the package (hello.R in this simple example) onto the template. My question is how to get Quarto or RMarkdown template (skeleton.Rmd) to automatically open in a way the user can edit the template to their specific circumstances?

Sorry I don't understand how your package is working. it seems to use usethis but not within a function that a user can call.

Also if you want to create R Markdown template, some information are at R Markdown Document Templates

This also gives info on RMarkdown templates

overall be sure to have something that work with R Markodwn for example, and try to make it work for Quarto.

Hi, thanks for the note.

Some good news. I have professional level skills in graphic design. It would be very easy for me to give a 3-day seminar on graphic design for data scientists, and a week long workshop on video + audio + motion graphics for data scientists.

As far as this project, once I'm done with this part of my package, a friend is going to help finish the design. He was faculty with one of the world's finest design schools - the School of the Art Institute of Chicago. I don't need any help with the template, or design, or anything like that.

I can design any template in RMarkdown or Quarto, and produce works with levels of design that blow away anything I've ever seen from anyone else using RMarkdown or Quarto. I can also export R data and import it into professional design tools so I can use layers, professional fonts, spot colors, and all the professional tools.

Designing the template was never the question or issue or problem. My apologies if that was not clear previously, hopefully this communication is better!

The question I'm working on is this: The package will run some processes with the data, put the results of analyses into the template. The question I can't find an answer to is how to have R package automatically open the template that contains the results of the analyses, in a way that the user can edit it.

I saw a demo 30 years ago where QuarkXPress did this (obviously without R or Python), and it was extremely easy. InDesign and Affinity Publisher can do it, too. I can harness the full power of R and combine that with professional publishing software (I use Affinity Publisher), so designing a template is no problem. The difference here is I'm harnessing the full power of R to generate the results on its own, so any R user can do this.

Once that's done (and the R part is completely done, no need to ask if I need help there, I don't), how do I have my R package open the template which includes the results generated, so the user can edit it?

Think of a very very simple mail merge. The R package will generate the results based on data. The package will put the results of all the analyses into the template. (that all currently works perfectly, no help needed). Once all of that is done, the question is finding out exactly how the R package will open the template with the new results so the user can edit the company name (or whatever) and then distribute it. That's all it is. Not complicated, and it's been possible for 30+ years on other platforms.

How can I have the R package open the template (RMarkdown or Quarto) with the results of the analysis, so the user can edit it?

If a template is the wrong way to do this, that's perfectly fine. How is this done within R?

Thanks for all the kind help, please let me know if this is not clear, I'm happy to clarify anything!

Just for fun, here is an example of a design I did when I was a data science student, that uses good design principles. This is an example of what data science can look like. My professor at Northwestern University said this was designed so well it could easily go to a CEO or Board of Directors. While it's not the format for a research publication, there is a definite place for work with this level of design in the data science community to communicate the results of our work with interested parties. Thanks!
conte_wine_data_analysis_using_SAS.pdf (1.1 MB)

1 Like

This topic was automatically closed after 45 days. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.