How to run a julia chunk in RMarkdown

Viewed 991

I am trying to run a Julia chunk in RMarkdown. I am using the package JuliaCall. Here are the steps I've completed:

  1. Downloaded Julia
  2. Installed JuliaCall
  3. Run the code julia_setup(JULIA_HOME = "C:/Users/James/Documents/Julia 1.5.1/bin")
  4. Run julia <- julia_setup()

Here is a minimal example of my RMarkdown file:

---
title: "julia_eg"
author: "James"
date: "9/23/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

this is a julia example

```{julia}
a = sqrt(17)
a
```

When I try and knit this, it tells me it cannot find Julia - I get this error:

Error in julia_locate(JULIA_HOME) : Can not find the Julia installation in the default installation path 'C:\Users\James\AppData\Local' Calls: <Anonymous> ... withVisible -> eval -> julia_setup -> julia_locate

So clearly my running of julia_setup in step 3 above didn't have the desired effect - even though it did run this for sometime and told me that it had completed that task.

Is there a more straightforward way of getting it to find Julia?

1 Answers

Rmarkdown is only aware of any code that is run in the immediate session, to avoid creating documents that will be impossible to compile by itself.

As such you'll have to add the code to the initial code chunk

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
Julia_setup(JULIA_HOME = "C:/Users/James/Documents/Julia 1.5.1/bin")
julia <- julia_setup()
```
Related