Blogging with runnable Python in Rmarkdown files
I wondered if I could blog with runnable Python code chunks if I’m creating my Hugo content with .Rmarkdown files. It looks like I can with the reticulate package; see the vignette here.
install.packages('reticulate', repos="https://cloud.r-project.org")
library(reticulate)
I believe this allows you to actually run Python. Alternatively, if you just want to display Python code, just use a code fence, i.e. the Github-style code block that’s 3 backticks, new line, code, then three closing backticks on a new line, like so:
x = [1, 2, 3, 4, 5]
print(x[0:4])
According to the reticulate vignette, you start by loading the package and specifying the python directory.
library(reticulate)
use_python("/usr/bin/python")
Ultimately though I could not get the following simple Python code to execute:
import pandas
This may be an issue of me not having pandas installed properly. Answering that question will have to wait until a later date.