Import R script plots and dataframes to an rmarkdown script

Hi everyone,

I am new to the R community and i have been learning by myself with online ressources the R language and some of its packages for a month or so with the aim to automate preliminar data processing in order to have an overview of experiemental results. I managed to process my data and now i wish to create a basic report that will contain plots and some of my dataframes.

I have learned how to import raw data from excel files, tidy and manipulate them as data frames using several of the tidyverse's packages and producing ggplots. I have created an Rproject in a way that helps me organise all my files.

Now I want to create a basic PDF or HTML report that will contain some of the dataframes and ggplots i have produced . After struggling with gridextra i think Rmarkdown could be an elegant solution to my problem. But as far as i've read on Rmarkdown's basics, i cant manage to import my r script objects and variables into my Rmd file. I know that i can save and load my r objects using save() and load() functions but it does not work when i use load() into my r chunks of code to import them.

Ps: i am working on Rstudio.

Can anyone help me on that matter, if you have any advices and ressources please share them i am all ears. Thanks in advance.

1 Like

Like you said, with Rmarkdown is a good tool for make reports and share better the code.

check this:

Im recomend you put in the first chunk all the libraries of work. And work with order for better understand.

1 Like

Hi M_AcostaCH thank you for your answer.
According to what i see in your screenshot you seem to do your R data manipulations directly in the code chunks of the Rmarkdown file. I wanted to really separate the data manipulations and the report. And as you can see in my screenshot, i just imported the r script of my rproject into the Rmarkdown file in order to select the objects of the global environement that it produced. To do so i used the R function source().
I dont know if its a good way to work but compartimentalize the different steps helps me.

1 Like

Ofcourse, you could put the data in one chunk, for run well the code, and when you make a Rmarkdown file put like hidden data. Its indicate that the data is not show in the final file but its necesary for run well the code.

I see that you use include=F, but in my case Im use echo=F for indicate that the run the chunk but dont show the script in the final file. In this case the plot run but not show the code.

Maybe you could use this for load the object or data, but dont show in the final file.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.