((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/R" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.")) (section 2 "R" (p "Interface to R") (toc) (section 3 (tt "R") (p (b "[module]") " " (tt "R")) (p "The R-module provides functions for applying and evaluating R-expressions.") (ul (li (int-link "#NA" "NA")) (li (int-link "#NA?" "NA?")) (li (int-link "#R" "R")) (li (int-link "#R*" "R*")) (li (int-link "#R->scheme" "R->scheme")) (li (int-link "#R-eval" "R-eval")) (li (int-link "#R-missing" "R-missing")) (li (int-link "#R-null" "R-null")))) (section 3 "Overview" (p (tt "R") " provides a simple way to call R-functions, consisting of the following two forms: " (tt "R") " and " (tt "R*") ". " (tt "R") " evaluates an R-expression, returning an opaque R-pointer that can be passed to other R-functions. Use this, for instance, when you don't need to modify the object in Scheme.") (p (tt "R*") ", on the other hand, evaluates the expression and tries to translate it into Scheme; it understands " (tt "NULL") ", lists, strings, reals, bools, complex numbers and symbols. Everything else is opaque.")) (section 3 "Documentation" (section 4 (tt "NA") (def (sig (constant "NA → (make-NA)" (id NA))) (p "NA corresponds to R's NA.") (highlight scheme "(define NA (make-NA))")) (section 5 "Examples" (p "Don't forget to quasiquote:") (pre "(R* (is.na (c 1 ,NA)))\n => #(#f\n =>   #t)\n"))) (section 4 (tt "R-missing") (def (sig (constant "R-missing → (foreign-value R_MissingArg SEXP)" (id R-missing))) (p "R-constant for missing arguments") (highlight scheme "(define R-missing (foreign-value \"R_MissingArg\" SEXP))")) (section 5 "Examples" (p "Selecting columns of matrices; corresponds to " (tt "sum(complete.cases(airquality[, -1]))") ":") (pre "(R* (sum (complete.cases (|[| airquality ,R-missing 1))))\n => 116\n"))) (section 4 (tt "R-null") (def (sig (constant "R-null → (foreign-value R_NilValue SEXP)" (id R-null))) (p "NULL") (highlight scheme "(define R-null (foreign-value \"R_NilValue\" SEXP))")) (section 5 "Examples" (p "Empty list is not null:") (pre "(R* (is.null (list)))\n => #f\n") (p (tt "NULL") ", on the other hand:") (pre "(R* (is.null ,R-null))\n => #t\n"))) (section 4 (tt "R") (def (sig (syntax "(R expression ...) → R-object" (id R))) (p "Evaluate R-expressions, but do not try to translate the final result into a native Scheme object; this is useful when you don't need to manipulate the object directly in Scheme.") (dl (dt (tt "expression")) (dd "An expression to evaluate") (dt (tt "...")) (dd "More expressions")) (highlight scheme "(define-syntax\n  R\n  (lambda (expression rename compare)\n    `(begin\n       ,@(map (lambda (expression) `(R-eval ,(list 'quasiquote expression)))\n              (cdr expression)))))")) (section 5 "Examples" (p "An example from " (tt "ggplot2") "; see " (link "https://raw.github.com/klutometis/R/master/doc/ggplot.png" "here") ":") (pre "(R (library \"ggplot2\")\n   (plot\n    (qplot (factor ($ mtcars cyl))\n           ($ mtcars wt)\n           xlab:\n           \"Number of cylinders\"\n           ylab:\n           \"Weight (lb/1000)\"\n           main:\n           \"1974 Motor Trend car-comparison\"\n           data:\n           mtcars\n           geom:\n           (c \"boxplot\" \"jitter\"))))\n => #<tagged pointer sexp 3951738>\n") (p "Another plotting example; see " (link "https://raw.github.com/klutometis/R/master/doc/plot.png" "here") ":") (pre "(let ((x (R (sort (rnorm 47)))))\n  (R\n   (plot ,x xlab: \"i\" ylab: \"Random normals\" type: \"s\" main: \"Primitive ECDF\")\n   (points ,x cex: 0.5 col: \"dark red\")))\n => #<tagged pointer sexp 1510958>\n"))) (section 4 (tt "R*") (def (sig (syntax "(R* expression ...) → Scheme-object" (id R*))) (p "Evaluate R-expressions and translate the final result into a Scheme object, where possible (cf. " (int-link "#overview" "overview") "); use this (as opposed to " (tt "R") ") when you need to manipulate the value in Scheme.") (dl (dt (tt "expression")) (dd "An expression to evaluate") (dt (tt "...")) (dd "More expressions")) (highlight scheme "(define-syntax\n  R*\n  (lambda (expression rename compare) `(R->scheme (R ,@(cdr expression)))))")) (section 5 "Examples" (p "An example using classical statistics:") (pre "(let* ((x (R (runif 100 0 10))) (y (R (+ 2 (+ (* 3 ,x) (rnorm 100)))))\n                                (df (R (data.frame x: ,x y: ,y)))\n                                (d (R (lm (as.formula \"y ~ x\") data: ,df))))\n  (R* ($ (summary ,d) \"cov.unscaled\")))\n => #(0.0423305190964232  -0.0064350404228672 -0.0064350404228672\n =>    0.00128082525122574)\n")))) (section 3 "About this egg" (section 4 "Author" (p (int-link "/users/klutometis" "Peter Danenberg"))) (section 4 "Repository" (p (link "https://github.com/klutometis/R"))) (section 4 "License" (p "BSD")) (section 4 "Dependencies" (ul (li (int-link "big-chicken")) (li (int-link "call-with-environment-variables")) (li (int-link "define-record-and-printer")) (li (int-link "hahn")) (li (int-link "matchable")) (li (int-link "moremacros")) (li (int-link "numbers")) (li (int-link "shell")))) (section 4 "Versions" (dl (dt (link "https://github.com/klutometis/R/releases/tag/0.1" "0.1")) (dd "Initial release") (dt (link "https://github.com/klutometis/R/releases/tag/0.1.1" "0.1.1")) (dd "Add cock.") (dt (link "https://github.com/klutometis/R/releases/tag/0.1.2" "0.1.2")) (dd "Clean up animation code.") (dt (link "https://github.com/klutometis/R/releases/tag/0.1.3" "0.1.3")) (dd "Set R_HOME, if necessary.") (dt (link "https://github.com/klutometis/R/releases/tag/0.2" "0.2")) (dd "R- and R*-forms.") (dt (link "https://github.com/klutometis/R/releases/tag/0.2.1" "0.2.1")) (dd "Use the new R-eval forms.") (dt (link "https://github.com/klutometis/R/releases/tag/0.2.2" "0.2.2")) (dd "With a note about cock-utils") (dt (link "https://github.com/klutometis/R/releases/tag/0.3" "0.3")) (dd "NA, NaN, inf") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.1" "0.3.1")) (dd "Rid of aima; NA in lists") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.2" "0.3.2")) (dd "Some examples in the docs") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.3" "0.3.3")) (dd "Using sjamaan's idea about integer instead of int for 32-bit machines.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.4" "0.3.4")) (dd "Multiple R-expressions") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.5" "0.3.5")) (dd "Blindly trying to fix NA for 32-bit.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.6" "0.3.6")) (dd "Add test-exit.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.7" "0.3.7")) (dd "Remove dependency on setup-helper-cock.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.8" "0.3.8")) (dd "Remove the dependency on debug.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.9" "0.3.9")) (dd "Remove the `debug?' parameter.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.10" "0.3.10")) (dd "Evaluate the examples.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.11" "0.3.11")) (dd "Use hahn.") (dt (link "https://github.com/klutometis/R/releases/tag/0.3.12" "0.3.12")) (dd "Specify hahn-version."))) (section 4 "Colophon" (p "Documented by " (int-link "/egg/hahn" "hahn") ".")))))