Created
November 30, 2020 16:02
-
-
Save cderv/7a012d0c83219ed8fba62b94a5ef072d to your computer and use it in GitHub Desktop.
R in lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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