Proper R Markdown Code Organization

前端 未结 2 1652
轻奢々
轻奢々 2021-01-13 13:55

I have been reading about R Markdown (here, here, and here) and using it to create solid reports. I would like to try to use what little code I am running to do some ad hoc

2条回答
  •  半阙折子戏
    2021-01-13 14:17

    Often times, I have many reports that need to run the same code with slightly different parameters. Calling all my "stats" functions separately, generating the results and then just referencing is what I typically do. The way to do this is as follows:

    ---
    title: "Untitled"
    author: "Author"
    date: "August 4, 2015"
    output: html_document
    ---
    
    ```{r, echo=FALSE, message=FALSE}
    directoryPath <- "rawPath" ##Something like /Users/userid/RDataFile
    fullPath <- file.path(directoryPath,"myROutputFile.RData") 
    load(fullPath)
    ```
    
    Some Text, headers whatever
    
    ```{r}
    summary(myStructure$value1) #Where myStructure was saved to the .RData file
    ```  
    

    You can save an RData file by using the save.image() command.

    Hope that helps!

提交回复
热议问题