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

Specifying Feature Set in R

We list the R input types for specifying set of features in a dataframe as learner parameters. Refer to IAI.FeatureSet for the Julia equivalence:

Input TypeDescriptionExamples
AllUse all columnslist(All = c())
Integer or a vector of IntegersSpecify indices of columns to use1, c(1, 3, 4)
String or a vector of StringsSpecify names of columns to use"x1", c("x1", "x3")
NotSpecify columns not to uselist(Not = 1), list(Not = c("x2", "x4"))
BetweenSpecify range of columns to uselist(Between = c("x1", "x4"))

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 have a finer-grained control of what is displayed for each node, such as adding summary statistics. We create a list of lists with the parameters controlling what you want to show in each node and pass this as extra_content:

node_inds <- iai::apply_nodes(lnr, X)
extras <- lapply(node_inds, function(inds) {
  list(node_details_extra = 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