Created
August 16, 2025 22:22
-
-
Save baptiste/759a1cafc3157b38bc7979b1994cdf0e to your computer and use it in GitHub Desktop.
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
[ | |
{ | |
"func": "metadata", | |
"value": { | |
"code": "x = 1 + 1", | |
"id": "a" | |
}, | |
"label": "<r-chunk>" | |
}, | |
{ | |
"func": "metadata", | |
"value": { | |
"code": "y = 2 + 2", | |
"id": "b" | |
}, | |
"label": "<r-chunk>" | |
} | |
] |
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
#let code(x, id: "a") = { | |
[#metadata((code: x.text, id: id)) #label("r-chunk")] | |
} | |
With this code, | |
#code(`x = 1 + 1`, id: "a") | |
or another | |
#code(`y = 2 + 2`, id: "b") | |
#let output = { | |
if "results" in sys.inputs.keys() { | |
json(sys.inputs.results) | |
} else { // default values | |
(x: 3, y: 4,) | |
} | |
} | |
`x` is #output.x | |
`y` is #output.y |
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
{"x":2,"y":4} |
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
library(jsonlite) | |
library(evaluate) | |
library(purrr) | |
inputs <- jsonlite::read_json("inputs.json") | |
e <- new.env() | |
walk(inputs, \(.x) evaluate(.x[["value"]][["code"]], envir = e)) | |
jsonlite::write_json(as.list(e), 'results.json', auto_unbox=TRUE) | |
Author
baptiste
commented
Aug 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment