Extract specific code chunks from a QMD/RMD file into a plain R script file

Hi code fam,

I am wondering if any of you have suggestions on how to solve this problem.

I have this project I'm working on where I document a workflow from end to end. I start with data ingestion and end up producing some research artifacts like reports and models. The Quarto file has a lot of explaining where I solve the same problem in different ways.

What I would like to do is at the end grab specific code chunks from the Quarto file and turn them into a plain R script file. Can you think of a way to accomplish this?

I'd appreciate whatever suggestion you can send my way,

Erwin

Hi @Erwin_Lares ,

tested Extract code with Quarto – Tutorial: Hello, Quarto hello.qmd. knitr::purl("hello.qmd") returns a hello.R file

## ---------------------------------------------------------------------------------------------------------------
#| label: load-packages
#| include: false

library(tidyverse)
library(palmerpenguins)


## ---------------------------------------------------------------------------------------------------------------
#| label: plot-penguins
#| warning: false
#| echo: false

ggplot(penguins, 
       aes(x = flipper_length_mm, y = bill_length_mm)) +
  geom_point(aes(color = species, shape = species)) +
  scale_color_manual(values = c("darkorange","purple","cyan4")) +
  labs(
    title = "Flipper and bill length",
    subtitle = "Dimensions for penguins at Palmer Station LTER",
    x = "Flipper length (mm)", y = "Bill length (mm)",
    color = "Penguin species", shape = "Penguin species"
  ) +
  theme_minimal()