【问题标题】:Rmarkdown - python inline code in RmarkdownRmarkdown - Rmarkdown 中的 python 内联代码
【发布时间】:2020-12-17 15:59:26
【问题描述】:

我正在将 Rmarkdown 与 python 一起使用。 python 的R 内联代码的等价物是什么? 例如,在https://rmarkdown.rstudio.com/lesson-4.html 我可以做

``r x`

在文本中显示 x 的值。但是如果我这样做了

``python x`

我刚收到短信python x

【问题讨论】:

  • 这就是我的选择!你能把它加进去让我接受吗?

标签: r-markdown reticulate


【解决方案1】:

不确定这是否可能。我发现的所有示例都使用 R 内联代码,如 `r py$x` 来实现这一点。参见例如rmarkdown cookbook

【讨论】:

    【解决方案2】:

    使用此解决方法,有可能:

    ```{r setup, include=FALSE}
    library(reticulate)
    ```
     
    ```{python include=FALSE}
    result = 1 + 1
    ```
     
    1 + 1 = `r py$result`    # 1 + 1 = 2
    

    其中py$result 的意思是:取名为result 的Python 变量的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-08
      • 1970-01-01
      • 2023-02-01
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      相关资源
      最近更新 更多