Skip to content

Instantly share code, notes, and snippets.

@HenrikBengtsson
Last active January 9, 2023 04:06
Show Gist options
  • Save HenrikBengtsson/0b9d43a9eebc78a58862 to your computer and use it in GitHub Desktop.
Save HenrikBengtsson/0b9d43a9eebc78a58862 to your computer and use it in GitHub Desktop.
RSP: Including file content in Markdown

RSP: Including file into Markdown

This can be done using the <%@include file="..."%> RSP preprocessing construct.

From R:

> R.rsp::rfile('main.md.rsp', postprocess=FALSE)
RspFileProduct:
Pathname: C:/Users/hb/braju.com.R/R.rsp/main.md
File size: 66 bytes
Content type: application/x-markdown
Has processor: TRUE

From the command line:

Rscript -e R.rsp::rfile main.md.rsp --postprocess=FALSE

or just

rfile main.md.rsp --postprocess=FALSE

if you add system.file(package='R.rsp', 'exec') to your PATH.

All outputs a file main.md:

# An Example

A list:
1. One
1. Two.
1. Three

That's it!

There's also rcat for outputting to standard output instead of writing to file.

Clarification: The <%@include ...%> construct is a preprocessing construct independent of the R language, i.e. there is nothing preventing this from being implemented in another language. This is in contrast to using <%=paste(readLines('child.md'), collapse='\n')%>, which is specific to R.

A list:

  1. One
  2. Two.
  3. Three
# An Example
<%@include file="child.md"%>
That's it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment