Differences between R and Julia

The IAI R interface matches the Julia API very closely, so you can refer to the Julia documentation for information on most tasks. On this page we note the main differences between the R and Julia interfaces.

Conversion of Julia data types to R

In order to figure out the types to pass to an IAI function from the R interface, you can refer to the equivalent function in the Julia API and translate the types to their R equivalent. Most literal data types convert in a straighforward manner, for example:

  • Int to integer (can also pass as a round-number double, e.g., 1.0)
  • Float64 to double
  • String to character
  • Dict to list

The following Julia types can be passed as follows:

  • nothing can be passed using NULL
  • a Symbol can be passed as a character
  • a Vector can be passed as an atomic vector
  • a Matrix can be passed as a matrix
  • a DataFrame can be passed as a data.frame

Interactive Visualizations

The write_html and show_in_browser functions work the same in R as in Julia for saving visualizations to file or displaying in an external browser, respectively. Additionally, visualizations will be automatically shown in the viewer pane when using RStudio, similar to how visualizations are automatically displayed in Jupyter notebooks.

Below is an example that shows the equivalent R code for the advanced visualization examples in Julia. In these examples we work with the following tree learner:

Optimal Trees Visualization

We can rename the features with a list that maps from the original names to more descriptive names:

vis_renamed_features <- iai::tree_plot(lnr, feature_renames = list(
  "disp" = "Displacement",
  "hp" = "Horsepower",
  "wt" = "Weight"
Optimal Trees Visualization

We can also add extra content for each node, such as summary statistics. We create a character vector with the content to show for each node and pass this as extra_content:

node_inds <- iai::apply_nodes(lnr, X)
extras <- sapply(node_inds, function(inds) {
  paste0("<b>Mean horsepower in node:</b> ",
         round(mean(X[inds, "hp"]), digits = 2))
vis_extra_text <- iai::tree_plot(lnr, extra_content=extras)
Optimal Trees Visualization

Finally, we can combine multiple learners into a single visualization as described in the Julia documentation. In R, a question is a single-entry named list of the form list(question = responses), where question is the string for the question and responses is itself a list of possible responses:

questions <- list("Use learner with" = list(
  "renamed features" = vis_renamed_features,
  "extra text output" = vis_extra_text
Optimal Trees Visualization