---
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")
```
