Open rcst opened 3 years ago
I've been thought about this before.
I concluded the syntax like `maxima 1+1;`
is not a good idea because
addition of engines certainly make authors difficult to distinguish which inline code need the evaluation.
If I were to implement, I'd implement `1+1;`{maxima}
which is more consistent with the syntax of chunk and may allow additional chunk options.
About the current implementation,
I agree with @atusy. I tend not to generalize the syntax `r `
to other engines. I'm not totally comfortable with the syntax for inline expressions since it's not unique enough. People might write literal code like `r = sqrt(x^2 + y^2)`
, which doesn't mean inline R code. If I generalize the syntax to other languages, the potential ambiguity can bite users harder.
Is there a workaround?
I don't know anything about the rim package you mentioned. If it provides a way to access maxima variables or run maxima code from the R session, your problem would be solved. The reticulate package is a good example, e.g., you can use reticulate::py
to access Python objects. However, you mentioned that rim::maxima.get()
uses a different maxima session: https://stackoverflow.com/questions/68283952/knitr-inline-code-chunk-of-foreign-engine#comment120684378_68283952 Then perhaps there isn't a workaround.
If I were to implement, I'd implement
`1+1;`{maxima}
which is more consistent with the syntax of chunk and may allow additional chunk options.
More consistent with both the current syntax and the chunk syntax would be `{engine_name} foo`
. If this were introduced, `r foo`
could then become a shortcut for `{r} foo`
.
`{engine_name} foo`
is interesting.
However, I still say `foo`{engine_name}
because this syntax is more consistent with Pandoc's inline code with attributes (e.g., `knitr::knit(x)`{.r}
)
Thanks for your suggestions. I solved this issue by implementing a wrapper maxima.inline()
that accesses the Maxima session used for the knitr-engine. So the user can do
`r maxima.inline("1+1;")`
I think that's sufficient for this issue.
`{engine_name} foo`
is interesting. However, I still say`foo`{engine_name}
because this syntax is more consistent with Pandoc's inline code with attributes (e.g.,`knitr::knit(x)`{.r}
)
Just adding here that in Quarto, the inline syntax is now
`{r} x`
`{python} x`
and not the attribute version
So it would make sense to support similar syntax natively (currently Quarto is doing the transformation from `{r} ...`
to `r ... `
Interesting. It happens that I did the same thing in litedown (in theory, inline code can use any language). Also I added support for chunk options for inline code, e.g., `{r, eval=FALSE} x`
.
I have posted this question on SO.
I've written a knitr engine to process Maxima code (as part of a package), which works for "regular" chunks just fine, e.g.:
(%i1) 1+1;
(%o1) 2
maxima 1+1;