Skip to content

Instantly share code, notes, and snippets.

@cderv
Created November 30, 2020 16:02
Show Gist options
  • Save cderv/7a012d0c83219ed8fba62b94a5ef072d to your computer and use it in GitHub Desktop.
Save cderv/7a012d0c83219ed8fba62b94a5ef072d to your computer and use it in GitHub Desktop.
R in lua
---
title: "Use R in a lua filter"
output:
html_document:
pandoc_args: !expr rmarkdown::pandoc_lua_filter_args("my.lua")
---
This document will have uppercase header using R function `toupper()`
```{cat, engine.opts = list(file = "my.lua")}
function Header(el)
cmd = os.getenv("R_HOME").."/bin"..os.getenv("R_ARCH").."/Rscript"
print(cmd)
return pandoc.walk_block(el, {
Str = function(el)
out = pandoc.pipe(cmd, {"dummy.R"}, el.text)
print(out)
return(pandoc.Str(out))
end
})
end
```
```{cat, engine.opts = list(file = "dummy.R")}
cat(toupper(readLines('stdin', warn = FALSE)))
```
# Something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment