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

Allow numeric values for fig.keep to index plots #1265

Closed
ClaudiusL opened this issue Aug 8, 2016 · 5 comments
Closed

Allow numeric values for fig.keep to index plots #1265

ClaudiusL opened this issue Aug 8, 2016 · 5 comments
Labels
feature Feature requests
Milestone

Comments

@ClaudiusL
Copy link
Contributor

This is a feature request based on this question on SO.

So far, fig.keep accepts only 'high', 'none', 'first', 'last' (and, implicitly, 'all') . Would it be possible to extend the functionality in a way similar to echo, such that fig.keep = c(1, 3) keeps the first and the third plot?

One potential drawback is that fig.keep = c(1, 3) cannot be combined with fig.kepp = 'high'. Therefore, the indices would implicitly always refer to low-level plots. (The same already applies to fig.keep = 'first').

I think the implementation could be quite simple: In block.R, line 222, an additional if clause could be added:

if (keep %in% c('first', 'last')) {
  res = res[-(if (keep == 'last') head else tail)(which(figs), -1L)]
} else {
   if (is.numeric(keep)) { #new 
     res = res[which(figs)[keep]]
    }
  # merge low-level plotting changes
  if (keep == 'high') res = merge_low_plot(res, figs)
}

However, I am not entirely sure about the contents of res and figs, so my suggested code might be wrong.

@yihui yihui added the feature Feature requests label Aug 8, 2016
@yihui
Copy link
Owner

yihui commented Aug 8, 2016

That looks okay to me. Could you submit a pull request? Thanks!

@yihui yihui added this to the v1.14 milestone Aug 8, 2016
ClaudiusL pushed a commit to ClaudiusL/knitr that referenced this issue Aug 9, 2016
ClaudiusL pushed a commit to ClaudiusL/knitr that referenced this issue Aug 9, 2016
@ClaudiusL
Copy link
Contributor Author

I also proposed an update for http://yihui.name/knitr/options/. Should this be a separate pull request? (Not sure about the correct workflow for this.)

@yihui yihui closed this as completed in c05523b Aug 9, 2016
@yihui
Copy link
Owner

yihui commented Aug 9, 2016

Yes, the docs are in the gh-pages branch. Please submit a separate PR for that. Thanks!

@ClaudiusL
Copy link
Contributor Author

Ok. Slowly I'm getting used to how this works … ;)

@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
feature Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants