Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting code from an RMarkdown document #18

Open
francojc opened this issue Feb 7, 2019 · 0 comments
Open

Extracting code from an RMarkdown document #18

francojc opened this issue Feb 7, 2019 · 0 comments
Labels
Tips Tips for the community

Comments

@francojc
Copy link

francojc commented Feb 7, 2019

In our last session I mentioned that there is a way to extract the code, which is contained in the code chunks, from an RMarkdown document. The purl() function from the knitr package will do this.

Imagine your have an RMarkdown file analysis.Rmd. You will specify the input path to this file and then the path to the file you wish to create.

knitr::purl(input = "analysis.Rmd", output = "analysis-code.R")

The output in the analysis-code.R file, by default, will only include those comments which appear inside a code chunk -other markup and prose will not. The purl() function has other options that you can tweak. Take a look at the documentation if you'd like to explore this function with ?knitr::purl.

@francojc francojc added the Tips Tips for the community label Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tips Tips for the community
Projects
None yet
Development

No branches or pull requests

1 participant