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

Create stitch example with chunk names and options? #33

Closed
wibeasley opened this issue Sep 30, 2014 · 6 comments
Closed

Create stitch example with chunk names and options? #33

wibeasley opened this issue Sep 30, 2014 · 6 comments
Labels

Comments

@wibeasley
Copy link

@yihui Is it possible to create a stitch example (like example 102), but with chunk options? I haven't seen a complete stitching example on any blog, in this repository, or in the demos in the knitr's inst/examples.

Stitching is working for me if I don't divide by chunks, but I'm doing something wrong when I either (a) separate them into chunks, or (b) set options (like the figure path, or the figure width).

The chunks are recognized with I replace '+ with ## @knitr. But the relative paths for the images don't work, so they're not being embedded in the html as base64.

An example might illuminate my mistakes (and hopefully helps others). Tell me if you want this posed to Stack Overflow instead of a GitHub issue.

knitr::stitch_rmd(
   script="./Manipulation/stitch-test.R", 
   output="./Manipulation/StitchedOutput/stitch-test.md"
)

This is one attempt, which was modified from the existing stitch example.

## title: A test script for the function stitch()
## author: Yihui Xie

# This chunk mimics the *spinning* example at https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R#L6-L8
#+ setup, include=FALSE
knitr::opts_chunk$set(fig.path='./stitch_output') 

#+ generate_scores
set.seed(1121)
(x=rnorm(20))

#+ calculate_descriptives
mean(x);var(x)

#+ plot_box, fig.width = 2
boxplot(x)

#+ plot_histogram, fig.width = 6
hist(x,main='')
@yihui
Copy link
Owner

yihui commented Oct 14, 2014

Sorry, but no, stitch() does not support chunk options.

@wibeasley
Copy link
Author

Thanks for clarifying that, @yihui. I considered that possibility for a second, but these two entries in the NEWS file made me keep trying ways to get it working. I've submitted yihui/knitr#856 so hopefully you won't have to spend time on this question again.

NEWS:

- fixed #487: `stitch_rhtml()` and `stitch_rmd()` should not use the chunk option `out.width = '.6\\linewidth'` (thanks, Tal Galili)
...
- `stitch()` accepts labeled R scripts now; if an R script contains chunk headers of the form `## @knitr label, options`, they will be used in the template (#411) (thanks, @jamiefolson)

@yihui
Copy link
Owner

yihui commented Oct 14, 2014

Ah, sorry, it looks like I have a regression bug somewhere. I'll look into it. Thanks for pointing it out. I even have forgotten I implemented this once :)

@wibeasley
Copy link
Author

I'm glad you said that. I thought my stitch scripts had been working at one point, but then thought that I must have misremembered the spin/stitch distinction or something.

It's funny, but the spin & stitch functions were some of my favorite things when reading your knitr book last year. I use knitr a lot, and was already familiar with most o fthe book's lessons (although I use it so much, its certainly worth my time to review them). But those two functions had escaped my attention until the book.

Stitch and spin fits such a nice need for when I want to record the results of a data manipulation (eg, how many missing values & successful/unsuccessful matches between record sets), but it's not really worth creating a separate Rmd file for. It's nice how knitr offers these light-weight derivative functions (instead of always requiring the user to use the full-blown approach) to adapt to the trade-offs of different scenarios.

@yihui
Copy link
Owner

yihui commented Oct 14, 2014

Okay, I just double checked it and the answer is no, I did not implement it. The NEWS item was misleading. Only chunk labels are supported, and chunk options are not. That said, I guess it is not too difficult to implement it anyway. Please open a new issue in the knitr repository so I will not forget it. Thanks!

@wibeasley
Copy link
Author

Cool. Then I guess I was simply misremembering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants