As the UEFA Euro 202(0/1) is going on, I was inspired to check out a dataset of all international men’s football matches since the dawn of time. This post goes over some questions I had for the dataset, and how I approached the analysis with my recent macro package DataFrameMacros.jl. Plotting is done with AlgebraOfGraphics.jl, which is a super useful grammar-of-graphics style package building on Makie.jl, which I’m a co-author of and which is therefore my preferred plotting package.
Since Julia has a younger ecosystem, you won't always find the functionality you need for every task. In those cases, you're left with the choice to either:
Implement it yourself.
This is great for the Julia community in the long run (especially if you release your work as a package! Please do this!), but you don't always have the time/energy to do so.
Use a package in another language.
Language wars are boring. You should use all the tools at your disposable. You don't need to stick with Julia for everything (especially since interop is easy!).
Particularly for niche models in the field of statistics, you'll often find R packages that do not have Julia counterparts. Thankfully, Julia and R work together rather seamlessly through the help of one package.
After installing and typing using RCall, you'll have access to the R REPL Mode by typing $. Your prompt will change from julia> to R> and now all of your commands will run in R instead of Julia. You can use it just like a normal R session.
julia> using RCall
# type `$`
R> install.packages("ggplot2")
R> library(ggplot2)
R> data(diamonds)
R> ggplot(diamonds, aes(x=carat, y=price)) + geom_point()
If you want to call R from Julia in a non-interactive manner (not from the REPL), you can use @R_str macro:
julia> R"y = 2"
RObject{RealSxp}
[1] 2
Sending Julia Variables to R
The @rput macro sends a variable to R and uses the same name.
julia> x = 1
1
julia> @rput x
1
R> x
[1] 1
You can interpolate Julia values in @R_str commands as well as the R REPL Mode:
You now know the basics of working in R from Julia. There are deeper depths to dive into on the topic (such as type conversions between R and Julia), but this should give you a start on using your favorite R package together with Julia.
Enjoying Julia For Data Science? Please share us with a friend and follow us on Twitter at @JuliaForDataSci.