Rmd: \input LaTeX equivalent

Viewed 45

LaTeX function

\documentclass{article}
\begin{document}
\input{folder/file.tex}
\end{document}

\input{folder/file.tex} command in LaTeX fetches the text in the file from the folder. When the main file is run, all the text from file.tex is compiled and included.

Rmd - desired output

I am using R Markdown for my project. I desire to develop and document different topics in different files.

I want to have the following directory structure:

main.Rmd
main_directory
    code
        file1.Rmd
        file2.Rmd
    figures
    data
    read_me

Explored pathways

I have explored the following routes to achieve this.

As suggested in Link 1

sys.source(file = file.path(getwd(), "main_directory", 
                        "code", 
                        "file1.r"))

Here, the code text is not included in the output HTML knit from the Rmd.

```{r, child=file.path(getwd(), "main_directory", "code", "file1.Rmd"}
```

It led to the following error:

Error: attempt to use zero-length variable name

Here, the code text is not included in the output HTML knit from the Rmd.

```{r}
includeMarkdown(file.path(getwd(), "main_directory", "code", "file1.Rmd"))
```

It also led to the following error:

Error: attempt to use zero-length variable name

Question: How to include the Rmd code into main file similar to LaTeX input

0 Answers
Related