-
Notifications
You must be signed in to change notification settings - Fork 339
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
spacing between input R code and its output #189
Comments
The issue about removing the border can be solved by switching The space issue is related to hook1 <- function(x){ gsub("```\n*```r*\n*", "", x) }
hook2 <- function(x){ gsub("```\n+```\n", "", x) }
knit_hooks$set(document = hook2) |
thanks!! this is what i was looking for. i'm a newbie with knitr/slidify and i could not tell whether this was a knitr or a slidify issue. collapsing code and output actually brings another such issues because i'd like disable code coloring in R output and color in gray all R output to make it more distinguishable from input, without using the leading comment '##' or prompt '>' which knitr allows one to set. i'd say it looks initially to me as a knitr issue but i guess tuning the coloring should depend on whether output is latex or html5 and, in the latter, for the purpose of using slidify, i guess i would have to tweak with some custom CSS file in 'assets/css'. do you have some hint about how could i do this? thanks again! |
Slidify uses I will post more details on this when I find time. |
i'm using github as hitheme so i guess i should be looking to Regarding the |
Here is one approach which might work. Try including the following knitr chunk in your knitr document. It adds a I tested it and it works. knit_hooks$set(output = function(x, options) {
if (knitr:::output_asis(x, options)){
return(x)
}
stringr::str_c('\n\n```no-highlight\n', x, '```\n\n')
}) code.no-highlight {
color: #ccc;
} |
Feel free to reopen the issue if the problem remains unresolved at your end. |
Thanks for the code snippet. Indeed it works perfectly under the default behavior of In
and by the fact that Sweave would not put as much as space between different i/o R chunks. The look and feel I'm trying to achieve would be something along the lines of the following slides of mine I produced last year for a BioC lab at http://www.bioconductor.org/help/course-materials/2012/BioC2012/qpgraphWorkshop.pdf In my view it does not make sense to try to highlight R output using R rules since the output of an R function does not have to conform to any kind of R syntax and for this reason I find the highlighting of output a bit disturbing, at least for slides. |
Try adding the following CSS snippet to your Rmd file. A negative bottom margin for the <style>
pre {
margin-bottom: -10px;
}
</style> |
Thanks again for the hint. It solves the issue partially because I want the inner chunks of R code and their output to stick together but I want some margin with the text that may come before or after. Throughout this discussion I've come to understand better how the interplay between slidify and knitr works and I came up with the following solution which is a combination of all your suggestions, just in case is useful for anyone. I guess it can be improved in a number of ways.
Now if I type in my Rmd file something like:
It will put all R code and output together (i.e., without spacing between input R code and its output) and preserving the syntax highlighting for the input R code. Thanks again for all your help! I would not have made it so far! |
Glad you could make this work. Your code can be made more concise. I will post an update on how to make it concise when I find time. But since this works, thats terrific. |
I was thinking that since |
That is a great suggestion! I will try to figure out the least intrusive way to make this happen, based on the code you have provided in your comment. |
Similarly, relatively common R output, such as the summary of a linear model, does not fit on one slide. Is there an easy way to reduce the font of highlighted code in order to get the output to fit on the slide without spilling over the bottom margin? Thanks! |
Add CSS. pre {
font-size: 11px;
} This would reduce the font size for code on all slides. If you want to reduce it only on some slides, you could add the following css slide.smallcode pre {
font-size: 11px;
} and in your slide, you can add
|
Excellent! Thank you! |
hi,
is it possible to control (reduce) the spacing between input R code and its output?
3 lines of R code within backquotes, such as:
1:10
1:10
1:10
occupy an entire slide when the R output is appended. I'd like slidify to use less space between intput R code and its output, also removing the border. I guess it must be embarrasingly simple, I've googled around and searched for issues here, but could not find anything related.
thanks!!
robert.
The text was updated successfully, but these errors were encountered: