Marquette University
SCoRT - Summer 2025





































plot(lm(...))learner$train()mlr3, R6, S7UseMethod()setClass() and @shiny| Sys. | Style | Used In | β Pros | β οΈ Cons |
|---|---|---|---|---|
| S3 | Functional | Base R | Simple, extensible | No schema, fragile |
| S4 | Formal | Bioconductor | Type-safe, robust | Verbose, complex |
| R6 | Encapsulated | Shiny, Keras | Fast, mutable | Weak type safety |
| S7 | Unified OOP | Modern dev | Combines S3 & S4 benefits | Still evolving |
shinyapps.io, Posit Connect, university serversreactive(): memoized reactive expressionsisolate(): break reactive chainsobserveEvent(): trigger actions without outputslibrary(Rcpp)
cppFunction('
NumericVector hankelize_rcpp(NumericMatrix X) {
int L = X.nrow();
int K = X.ncol();
int N = L + K - 1;
NumericVector result(N);
NumericVector count(N);
for(int i = 0; i < L; i++){
for(int j = 0; j < K; j++){
result[i + j] += X(i,j);
count[i + j] += 1;
}
}
for(int i = 0; i < N; i++){
result[i] /= count[i];
}
return result;
}')library(microbenchmark)
# Large random matrix (e.g., 100 x 1000)
set.seed(123)
X_large <- matrix(runif(1e5), nrow = 100, ncol = 1000)
bench <- microbenchmark(
R_version = hankelize_R(X_large),
Rcpp_version = hankelize_rcpp(X_large),
times = 10
)
print(bench)
># Unit: microseconds
># expr min lq mean median uq max neval
># R_version 21225.1 21550.8 26604.53 25180.35 30969.3 34455.1 10
># Rcpp_version 176.9 177.8 299.87 194.50 253.7 1161.3 10π Native Python
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
mlp = MLPClassifier(hidden_layer_sizes=(10,))
mlp.fit(X_train, y_train)
y_pred = mlp.predict(X_test)π¦ R with reticulate
library(reticulate)
sklearn <- import("sklearn")
model_selection <- sklearn$model_selection
neural_network <- sklearn$neural_network
X <- as.matrix(iris[, 1:4])
y <- as.integer(iris$Species) - 1
train_test <- model_selection$train_test_split(X, y, test_size = 0.2, random_state = 42)
X_train <- train_test[[1]]
X_test <- train_test[[2]]
y_train <- train_test[[3]]
y_test <- train_test[[4]]
mlp <- neural_network$MLPClassifier(hidden_layer_sizes = tuple(10L))
mlp$fit(X_train, y_train)
y_pred <- mlp$predict(X_test)reticulate?π§° Why build a package?
mypkg/
βββ DESCRIPTION # π Package metadata
βββ NAMESPACE # π Exported functions & imports
βββ R/ # π Your R functions
βββ man/ # π Auto-generated documentationπ‘ Other folders you may add:
R packages transition through five development states:
R CMD check with:
devtools::release()π Good news!
π§± CRAN has built binaries for major platforms (Windows, β¦).
π Your package is now live! Searchable and installable via:
π§° Git = Local tracking tool
βοΈ GitHub = Online hosting and teamwork platform
π― A typical work cycle for package developers:
| Step | Description |
|---|---|
| βοΈ Edit | Make changes to .R or .Rmd files |
| β Stage | Select files to track in Git tab |
| π¬ Commit | Save with a message (e.g., βFix bugβ) |
| π Push | Send to GitHub |
Questions & Discussion