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

Calling purl from within a knit document #332

Closed
csgillespie opened this issue Jul 12, 2012 · 5 comments
Closed

Calling purl from within a knit document #332

csgillespie opened this issue Jul 12, 2012 · 5 comments
Labels
bug Bugs
Milestone

Comments

@csgillespie
Copy link
Contributor

If we include purl call within a knitr document, i.e.

<<echo=FALSE>>=
library(knitr)
purl("tmp.Rnw")
@

we get a duplicate label error.

@yihui yihui closed this as completed in f3adcc5 Jul 13, 2012
yihui added a commit that referenced this issue Jul 13, 2012
@yihui
Copy link
Owner

yihui commented Jul 13, 2012

should be fixed now

@adammwilson
Copy link

Is it possible to include the purl'ed .R file as an additional 'output' format without calling purl() separately from within RStudio? This would be nice for automatically generating both a markdown version and a runnable script at the same time (without worrying about file names, etc.). So, something like this:

---
title: "knit and purl"
output:
  md_document:
    variant: markdown_github
  r_script  

---

@adammwilson
Copy link

Answering my own question (in a way), it's possible to achieve my objectives with the following chunk:

'''{r, echo=FALSE, message=FALSE, results='hide', purl=FALSE}
input  = knitr::current_input()  # filename of input document
output = paste(tools::file_path_sans_ext(input), 'R', sep = '.')
knitr::purl(input,output,documentation=2,quiet=T)
'''

A little clunky, but 5 extra lines isn't too bad... Be careful that the purled version may not result in identical outputs as it does not include in line comments. See various threads about this (e.g. #812 (comment)).

@phoede
Copy link

phoede commented Oct 24, 2017

I tried to include a purl call when knitting a .Rmd file and I get a duplicate label error.
I have found a question on https://stackoverflow.com/questions/36868287/purl-within-knit-duplicate-label-error , so I should not be the only one.
Any ideas?

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

4 participants