-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Equivalent of oldbookdown::screenshot() #38
Comments
For the image size, |
Take http://r4ds.had.co.nz/introduction.html#rstudio. That section contains two screens, one of the R console and one of the options pane. They are currently displayed as the same width - but "rstudio-layout.png" is 2466 pixels wide and "rstudio-workspace.png" is 1350 pixels wide. Rather than inspecting (You might wonder if 11" is too wide - and indeed I think it is. I probably need to redo the screenshot at a more reasonable size, but I didn't realise until now because Another use case is http://r4ds.had.co.nz/relation-data.html#understanding-joins. Here I have hand drawn diagrams that have different widths, but with a consistent font size. Unless I manually adjust the Does that make sense? I'm fairly confident that this is different enough from the current behaviour of (I could've sworn that |
On closer inspection, I realized this was a bug of |
Ok, that's much better 👍 But setting the dpi chunk option doesn't seem to affect the output size? |
Right. |
@yihui could you make it work for this too? I think it is moderately important. |
…PNG/JPEG images using the same ratio rstudio/bookdown#38
Done in the dev version of knitr. |
Upstream changes: CHANGES IN knitr VERSION 1.13 NEW FEATURES code chunks that generate metadata may be cached now; it requires htmlwidgets >= v0.6 and htmltools >= 0.3.3 if you cache code chunks that contain HTML widgets or Shiny inputs/outputs (#1158) when the output format is not HTML, HTML widgets used to fail to render; now knitr will try to generate static screenshots for HTML widgets automatically using the webshot package; you can specify alternative screenshots via the chunk option screenshot.alt (which takes a character vector of image paths), and pass more options to webshot::webshot() via the chunk option screenshot.opts, e.g. list(delay = 3, cliprect = 'viewport') added two functions include_url() and include_app() to embed URLs in the output (the latter is for Shiny app URLs); when the output format is HTML, iframe will be used; otherwise screenshots of the URLs will be used screenshotting for HTML widgets and URLs can be forced for all output formats via the chunk option screenshot.force = TRUE; if you set the chunk option screenshot.force = FALSE, knitr will just render these content normally and not take screenshots added a new chunk option fig.link, which can be used to attach hyperlinks on figures, e.g. you can add a link to a screenshot of a Shiny app so that readers can check out the actual live app after clicking on the static screenshot (this chunk option currently only works for Markdown and LaTeX output) syntactical errors in code chunks will be allowed when the chunk option error = TRUE and the package version of evaluate is at least 0.8.4; previously knitr would just stop on parsing errors (r-lib/evaluate#65) PNG/JPEG images included via include_graphics() also respects the chunk option dpi now; if it is numeric and the chunk option out.width is not set, the output width (in inches) of an image will be automatically calculated from the actual width (in pixels) divided by dpi; note this feature requires the packages png and/or jpeg to be installed, and you can disable the feature using dpi = NA (thanks, @hadley, rstudio/bookdown#38) added a new hook function named evaluate in knit_hooks so that users can redefine a evaluator to evaluate the code chunk; the default is evaluate::evaluate(), and your custom evaluator must be compatible with evaluate::evaluate() in terms of the argument names and the data structure of the returned value (a list of values with special classes) added a new function combine_words() to combine multiple words / phrases into a single string, which may be useful in inline R expressions, e.g. combine_words(c('a', 'b', 'c')) returns a, b, and c render_markdown() gained a new argument fence_char to customize the character to be used as the code blocks fence, e.g. it can be a backtick, or a tilde, depending on the Markdown rendering engine (thanks, @tinyheero, #1161) the pandoc() function no longer assumes Markdown input (thanks, @scls19fr, #1170) added a new function knit_meta_add() so that users can manually inject metadata into the current knitr session for the tikz engine, if fig.ext = 'svg', dvisvgm will be called to convert the DVI output of TikZ to SVG; you need to install dvisvgm, and Windows users have to install GhostScript as well (thanks, @dkilfoyle, #1177) new js and css engines which surround their content with <script> and <style> tags respecitvely, and print no output when not in an HTML document for LaTeX tables, kable() supports short captions now via the caption.short argument, e.g. kable(..., caption = 'A long caption', caption.short = 'A short caption') (thanks, @ismayc, #1199) added three global R options knitr.sanitize.errors, knitr.sanitize.warnings, and knitr.sanitize.messages to mask or change the messages, e.g. if options(knitr.sanitize.errors = TRUE) and the chunk option error = TRUE, the actual error message will be replaced by a character string like "An error occurred"; these options can also accept character values so you can customize the messages to be displayed, e.g. options(knitr.sanitize.warnings = 'You had a warning from the code'); see rstudio/shiny#1123 for the motivation of these options BUG FIXES when the chunk option cache.rebuild = TRUE, the cache database should be rewritten (thanks, Oleg Mayba) include_graphics() did not work in inline R expressions (thanks, @WastlM, #1166) the cex parameter was not correctly restored in the case of opts_knit$set(global.par = TRUE) (http://stackoverflow.com/q/35606445/559676) for Rnw documents, when there are two instances of \documentclass{}, knitr might mistakenly treats the second instance as the the actual command to declare the document class (thanks, #1180, @ekstroem) corrected the environment for evaluating R scripts in stitch_rhtml() and stitch_rmd() (thanks, @hughan, #1207) MAJOR CHANGES the default value of the package option eval.after is changed from NULL to fig.cap, i.e. the figure caption will always be evaluated after a code chunk is evaluated (thanks, @JoshOBrien, #1165) the function eclipse_theme() has been removed since the website eclipsecolorthemes.org has been down for a long time
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. |
I don't think we have anything that's quite equivalent yet. There are two important differences from
knitr::include_graphics()
:r
for inline graphicsfig.width
andfig.height
)This is most useful for diagrams (so the
screenshot()
name isn't great), where you have carefully sized the image.The text was updated successfully, but these errors were encountered: