/
JuliaCall_in_RMarkdown.Rmd
51 lines (42 loc) · 1.32 KB
/
JuliaCall_in_RMarkdown.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
title: "JuliaCall in R Markdown"
author: "Changcheng Li"
date: "`r Sys.Date()`"
output:
rmarkdown::github_document
---
## Use JuliaCall as Julia Engine in R Markdown
To use `JuliaCall` package for julia engine in R Markdown document,
just set the language of the code chunk to be `julia`.
```{julia}
## This is a julia language chunk.
## In julia, the command without ending semicolon will trigger the display
## so is JuliaCall package.
## The julia display will follow immediately after the corresponding command
## just as the R code in R Markdown.
a = sqrt(2);
a = sqrt(2)
```
### Support for `Plots.jl`
`Plots.jl` is an easy to use and powerful julia package for plotting,
see <https://github.com/JuliaPlots/Plots.jl> for more detail.
Before the first time using `Plots.jl`, you first need to install the package like:
```{julia eval = FALSE}
import Pkg; Pkg.add("Plots")
```
After installation of the package, you can use it like this:
```{julia}
using Plots
gr()
plot(Plots.fakedata(50,5),w=3)
```
## Get Access to Julia in R Chunk
You can also get access to julia variables in R code chunk quite easily
using `JuliaCall`, for example:
```{r}
library(JuliaCall)
## This is a R language chunk.
## In the previous julia chunk, we define variable a,
## we can use functions in JuliaCall to get access to it.
julia_eval("a")
```