Error in loadNamespace(x) : there is no package called ‘JuliaCall’
Asked Answered
B

1

6

I just started to learn Julia in Quarto but when I run the following code in a Julia chunk in Quarto:

---
title: "Julia in Quarto"
editor: visual
format: html
---

```{julia}
# generating vectors
# x-axis
x = 1:10
 
# y-axis
y = rand(10)
 
# simple plotting
plot(x, y)
```

It returns:

Error in loadNamespace(x) : there is no package called ‘JuliaCall’

The error still appears even when adding:

using Pkg
Pkg.add("JuliaCall")

To the code chunk. Does anyone knows how to run the following Julia code in Quarto?


Please note: I use Rstudio

Belshin answered 18/12, 2022 at 9:57 Comment(0)
C
5

JuliaCall is an R package. Quarto executes Julia code using the IJulia Jupyter kernel. To use it, specify jupyter: julia_version in the YAML header. A Quarto installation guide is available.

To render Quarto documents that contain julia chunks

  1. start julia
  2. Enter package mode by pressing ].
  3. run Add IJulia
  4. Go back to the REPL (backspace), the default prompt after you start julia
  5. run using IJulia
  6. run notebook(). Use Ctrl+c or quitting julia to stop the Jupyter kernel.

If you don't have Jupyter installed at this point, this will be installed, refer to the above guide for details. This may take a while and prompt some input.

Now you should be able to render a document via the Quarto Cli from a shell and1 RStudio. For example, the following example.qmd should render and print a matrix.

---
title: "Bla"
jupyter: julia-1.8
---
```{julia}
[1 2 3]
```

This may a slow. Refer to the above guide on installing Revise.jl and using Jupyter Cache to speed things up. I personally experience speedup in using VSCode + Quarto extension over RStudio.


If not, the following allows R users to run julia code from within R and RStudio,

  1. in R, use install.package("JuliaCall")
  2. in R, run JuliaCall::julia_setup()

This takes care of some PATH variable and comes with the installJulia optional argument.

Chesney answered 18/12, 2022 at 11:45 Comment(2)
Thank you very much for your great answer! To only thing I did different was running import Pkg;Pkg.add("IJulia") in Julia mode. The rest worked perfectly, thanks!Belshin
@Belshin same outcome with different syntax, however, note that using - import is part of an ongoing discussion likely to change in Julia 2.0Chesney

© 2022 - 2024 — McMap. All rights reserved.