I hope this is in the correct forum. I am working on a project for a course.

I have this code (please see below) near the top of my .Rmd file and it knitr's just fine.

I need to make the output shorter (course requirement), so i was thinking of putting the code into an init function. Should one do this? Will it work?

I need the code to be run up front. I do want to show the code in the knitr document, but i would like to be in the appendix with the other code,

Any pointers will be appreciated.


Edit: looks like everything but the source can go into a function.

#install.packages('e1071')  # do once in R console.

Edit2: the code is now smaller:

{r} source("functions.R") initialize()


If you want the code to run but don't want it included set include=FALSE as shown below

```{r pressure, include=FALSE}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.