Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Output of Function in Rstudio (3.1.1) when Knitting to PDF

Tags:

markdown

r

knitr

I would like to limit the number of lines that are produced from a function when I knit my markdown document in R. I've looked around quite a lot but can't find a solution.

My code is below, it gives 50+ lines of data when run. My goal is to only have 9 lines of code produced by the sedist function.

```{r, results=1:9}
sedist(FILENAME, method="correlation")
```

I have tried using {r, message=1:9}, {r, Hide=1:9}, {r, height=1:9}, {r, results='hide'} and similar.

like image 592
TSMKDK Avatar asked Oct 05 '14 21:10

TSMKDK


People also ask

How do I knit to PDF in R?

When you press “Knit to PDF” in RStudio, it converts your R Markdown document into LaTeX. Download MiKTeX from here: https://miktex.org/download • Run the installer, and restart your computer. Open an R Markdown file in RStudio, and try knitting to PDF. You may be prompted to install some packages.

How do I change the output size in R?

To change the output size you can use the corresponding LaTeX commands, set just before the code junk. The smallest option would be \tiny . For a full overview consider e.g. this. After the code junk it's important to set back to the size you used before, e.g. \normalsize .

How do you stop knitting in R?

To exit early from the knitting process, you may use the function knitr::knit_exit() anywhere in the source document (in a code chunk or inline expression). Once knit_exit() is called, knitr will ignore all the rest of the document and write out the results it has collected so far.


1 Answers

Something like this??

```{r R.options=list(max.print=10)}
df <- data.frame(x=1:100,y=1:100)
df
```

The R.options chunk option in knitr allows you to set any of R's options locally for that chunk. Look at ?options for a list of the options you can set

like image 105
jlhoward Avatar answered Nov 14 '22 23:11

jlhoward