Skip to content

Latest commit

 

History

History
133 lines (90 loc) · 3.02 KB

File metadata and controls

133 lines (90 loc) · 3.02 KB

R to JuliaHub

By Kevin Bonham

Video 1

Youtube link

The data used in this video was generated with dummy_data.jl, and is in the tarball dummy_data.tar.gz.

The notebook that forms the basis of this tutorial series is in longitudinal-analysis.rmd

Video 2

Youtube link

VS Code extensions installed

Julia packages used

Julia commands

  • ] to enter the Pkg REPL (eg to add packages)
    • press backspace to go back to the regular REPL
    • activate . to activate the current directory as a Julia environment
    • st to show the status (eg which packages are installed)
    • add SomePackage to add a package to your environment
    • rm SomePackage to remove a package from your environment
    • instantiate if you have a Project.toml, and want to install all the packages in it (to eg reproduce an environment)
  • using SomePackage to load a package

VS-code setup

Once you have CondaPkg.jl installed, and have run conda install r-base in the Pkg REPL, you can link this installation to VS Code by updating the following parameters in your environment settings (.vscode/settings.json):

{
    "r.libPaths": [
        ".CondaPkg/.pixi/envs/default/lib/R"
    ],
    "r.rpath.linux": ".CondaPkg/.pixi/envs/default/bin/R",
    "r.rterm.linux": ".CondaPkg/.pixi/envs/default/bin/R"
}

Video 3

Youtube link

Set RCall library path

In the Julia REPL, run:

julia> ENV["R_HOME"] = joinpath(".CondaPkg", ".pixi", "envs", "default", "lib", "R")

julia> using Pkg; Pkg.build("RCall") # or '] build RCall'

RegEx magic to convert code cells from R to Julia

In VS Code, you can use the following regex to convert R code cells to Julia:

Capture:

```\{r(.+?)\}\n([\s\S]*?)```

Replace:

```{julia$1}\nR"""\n$2"""\n```

Video 4

Youtube link

R code to display a plot

p <- # platting code...
png("plot1.png")
print(p)
dev.off()

Using Julia to display a plot

  1. Add the packages Images.jl and FileIO.jl
using Pkg
Pkg.add("Images") #or `] add Images`
Pkg.add("FileIO") #or `] add FileIO`
  1. Use the following code to display a plot:
using Images, FileIO
load("plot1.png")

Video 5

Youtube link

Load dataframe from a CSV file

using CSV, DataFrames
jsubjects = CSV.read("dummy_subjects.csv", DataFrame)

Left join two dataframes

leftjoin(samples, subjects; on="subject"=>"subject_id")