-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.R
More file actions
44 lines (37 loc) · 1.38 KB
/
quickstart.R
File metadata and controls
44 lines (37 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env Rscript
# Quick Start Script for tinyoptics Development
#
# Run this script to load the package and try some examples
# Load the package from source (without installing)
cat("Loading tinyoptics from source...\n")
devtools::load_all()
cat("\n✓ Package loaded successfully!\n\n")
cat("=== Quick Examples ===\n\n")
# Example 1: Basic indexed traversal
cat("Example 1: Indexed traversal with named list\n")
prices <- list(apple = 1.50, banana = 0.80, orange = 2.00)
labels <- over_i(each_i, function(fruit, price) {
sprintf("%s: $%.2f", fruit, price)
}, prices)
print(labels)
cat("\nExample 2: Extract with indices\n")
print(extract_all_i(each_i, prices))
cat("\nExample 3: Numeric indices\n")
numbers <- list(10, 20, 30)
result <- over_i(each_i, function(idx, val) {
val * as.numeric(idx)
}, numbers)
print(result)
cat("\nExample 4: Data frame column operations\n")
df <- data.frame(x = 1:3, y = 4:6, z = 7:9)
result <- over_i(vars_i(is.numeric), function(col_name, col_data) {
cat(sprintf(" Processing column: %s\n", col_name))
col_data * 10
}, df)
print(result)
cat("\n=== Try Your Own Examples ===\n")
cat("The package is loaded. You can now experiment with:\n")
cat(" - over_i(optic, fn, data)\n")
cat(" - extract_all_i(optic, data)\n")
cat(" - each_i, cols_i(), vars_i(), filter_i()\n\n")
cat("Type your R code below or source this file and continue in the session.\n")