Home Comments Thread
New Thread

[knitr] Control output: Manipulate six types of chunk output and inline output | /knitr/demo/output/

yihui yihui 2022-12-16 22:25:01

Control output: Manipulate six types of chunk output and inline output

https://yihui.org/knitr/demo/output/

9 Comments

giscus-bot giscus-bot 2022-12-16 22:25:02
Guest *johnnyx* @ 2012-05-18 11:57:52 originally posted:

When I want to plot a certain function,  namely gevrlevelPlot( ), I also get output like min v  max that I want to supress. I only want to keep the plot but I can also not just externalize the plot. So is there a way for me to supress some of the results, but not all of them?> 

yihui yihui 2022-12-16 22:25:10

You need to figure out if they are normal text output, messages or warnings, and suppress them accordingly. Currently you can only choose the source code to show; other types of output can be turned either completely off or on.

Normally a plot function should not generate normal text output, so you may need to read the last section above and contact the author if he/she happens to be using cat().

Originally posted on 2012-05-18 13:33:46

giscus-bot giscus-bot 2022-12-16 22:25:03
Guest *Rivo* @ 2012-06-11 21:45:39 originally posted:

Hi.

I have a discrepancy (bad rounding) between console and report (even when 'asis' is set):

<>=
library(quantmod)
getSymbols("GS")
last(GS$GS.Close['2012-04']) #displays 115.15 in console and 115.2 in pdf
<>
 #sorry, I couldn't use the at sign as it's again and again changed to the name of one of the below commenters.

giscus-bot giscus-bot 2022-12-16 22:25:03
Guest *Blaine Mooers* @ 2012-09-29 14:38:57 originally posted:

My output goes past the right margin and up to the edge of the page before wrapping around. How can I get the output to stop at the right margin? 

yihui yihui 2022-12-16 22:25:11

try a smaller value for options(width)

Originally posted on 2012-09-29 21:15:03

giscus-bot giscus-bot 2022-12-16 22:25:04
Guest *Tal Bashan* @ 2012-10-10 03:01:17 originally posted:

My R output is quite long (stepwise regression) and I'd like to either make it smaller or crop it so it fits on the same page. How can that be done?
Thanks for your help,
Tal

giscus-bot giscus-bot 2022-12-16 22:25:05
Guest *Aaron Baggett* @ 2012-10-15 20:25:19 originally posted:

Yihui, 

The output from my R functions are overflowing past the right edge of the shaded area--even past the width of the page.  I've tried reducing the width in options setup, which, for some reason, does not seem to change the output printed by the R package's function.

My setup chunk is as follows:

<<setup, include="FALSE," cache="FALSE">>=opts_chunk$set(fig.path='figure/minimal-', fig.align='center', fig.show='hold')options(width = 90)

I'm using  <<tidy =="" true="">>= in the code chunk.

See pdfLaTeX screen here: http://goo.gl/NRtyn

Thank you for your help.

yihui yihui 2022-12-16 22:25:12

I cannot do much about that, because that is just what would have been shown in R console. Well, you can certainly try LaTeX tricks to break the long lines, or modify the fa() function so that it breaks those lines internally (e.g. with strwrap()), or design an output hook function in knitr to break the lines. None of these approaches are trivial (the third one might be the easiest), so I'd rather recommend you not to tackle at it.

Originally posted on 2012-10-16 06:25:20

giscus-bot giscus-bot 2022-12-16 22:25:06
Guest *Andy Teucher* @ 2013-01-17 23:55:12 originally posted:

Hello,

I'm having a bit of an issue using options eval=FALSE and echo=(a numeric vector) in an Rmd file.

The following produces an html file that returns just the first line (summary(cars)), and the output from all three, as expected:

summary(cars)  
str(cars)  
head(cars)  

However, if I change it to:

summary(cars)  
str(cars)  
head(cars)  

then all three lines show in the html file, while I would expect only the first line. I'm not sure if this is a bug, or if eval=FALSE then the script is not parsed into different expressions so that it reads the entire chunk as one expression... or if I'm missing something else...

It probably seems odd that I would want to do something like that, but I have a script which I am using in two different Rmd files. In each Rmd file I load the script using read_chunk, and in one Rmd file I need to execute the entire chunk (but hide some irrelevant code), while in the other Rmd file I want to hide the same bit of the chunk but not execute the chunk.

yihui yihui 2022-12-16 22:25:13

That is a bug; could you file it to https://github.com/yihui/knitr/issues? Thanks!

Originally posted on 2013-01-18 01:58:32

giscus-bot giscus-bot 2022-12-16 22:25:14
Guest *Andy Teucher* @ 2013-01-18 03:43:52 originally posted:

Done - thank you!

giscus-bot giscus-bot 2022-12-16 22:25:07
Guest *broesel* @ 2013-05-09 15:40:50 originally posted:

Hi Yihui,

I really appreciate knitr. Just one question:
What is actually the main reason, why long lines of text ouput are sometimes still too width, although options(width=60)?

I have tried all other solutions with listings etc., but from my point of view the default setting of knitr is the most beautiful and convenient one.

Do you think this is going to be solved by R soon? How can I contribute to find a solution for this problem?

Thanks in advance for an answer.

broesel

yihui yihui 2022-12-16 22:25:15

Sorry but there is no general solution to this problem. Some text output are not subject to the control of options('width').

Originally posted on 2013-05-25 07:18:35

giscus-bot giscus-bot 2022-12-16 22:25:08
Guest *fritsch* @ 2014-07-25 13:52:40 originally posted:

Hi,

the following chunk fails despite error=TRUE, i.e. knitr ends with an error instead of printing the chunk error message:

x<-rnorm(1)

if(x>=0)  
print("x größer oder gleich 0")  
else  
print("x kleiner als 0")  

Is there a different option that allows me to just output R errors? Is it a bug?

Thx
Stefan

yihui yihui 2022-12-16 22:25:16

That is a syntax error: you should not put else on a new line.

Originally posted on 2014-07-25 22:05:56

giscus-bot giscus-bot 2022-12-16 22:25:17
Guest *fritsch* @ 2014-07-28 09:44:03 originally posted:

Yes, but as far as I understand the idea of "error=TRUE" is that I will get that error message as output instead of knitr quitting on me.

"errors: option error (FALSE will make R stop if an error occurs; TRUE will show the error messages in the output)"

yihui yihui 2022-12-16 22:25:18

That does not include parsing/syntax errors. A code chunk has to be parsed before being executed, and the error option only applies to the errors during code execution.

Originally posted on 2014-07-28 18:33:48

giscus-bot giscus-bot 2022-12-16 22:25:19
Guest *fritsch* @ 2014-07-29 15:33:50 originally posted:

Ok, thx.

giscus-bot giscus-bot 2022-12-16 22:25:09
Guest *Gustav W Delius* @ 2014-11-15 10:49:00 originally posted:

This page describes how to have inline output of the results of R commands. But is it also possible to have inline chunks containing the formatted R code, similar to what chunk output does with the echo=TRUE, eval=FALSE option?

yihui yihui 2022-12-16 22:25:20

No.

Originally posted on 2014-11-15 21:14:20

Sign in to join the discussion

Sign in with GitHub