Primitives (=NetLogo commands) of the R extension of NetLogo.
Primitive | Desciption | Example |
---|---|---|
clear | Clears the R workspace, deletes all variables. | r:clear |
eval | Evaluates the submitted string in R, used for R function without a return value. | ;; create new vector x in R with a sequence from 1 to 10: r:eval "x <- seq(1,10)" ;; load an R package: r:eval "library(spatstat)" |
get | Gets a value from R; either submits a string including an R function with return value, or gets the value of a variable; return values can be strings, numbers, booleans, lists, or a list of lists. | ;; get value of variable x: r:eval "x <- seq(1,10)" print r:get "x" ;; save ten random values from binominal distribution in new local variable b: let b r:get "rbinom(10,1,0.5)" print b |
put | Creates a new variable in R with value(s) from NetLogo; submitted values/variables can be strings, numbers, booleans, or lists (NetLogo lists become R vectors, to create R lists see putlist). | ;; create an R variable r_var containing the value of NetLogo variable b: let b 12.95 r:put "r_var" b ;; create an R list r_turt containing the size of all turtles: r:put "r_turt" [size] of turtles |
putagent | Creates a list in R from variables of a set of NetLogo agents; collections of agent-variables can be stored in a single named list. | ;; create an R list r_patch containing the pxcor of patches: r:putagent "r_patch" patches "pxcor" ;; create an R list r_turtles containing the values of the variables who, size and colour of the turtles (agentset) with a value of who less than five: (r:putagent "r_turtles" turtles with [who < 5] "who" "size" "color") print r:get "r_turtles" print r:get "r_turtles$who" |
putagentdf | Same as putagent, but creates an R data-frame instead of a list because many R functions requires data frames as input. | ;; create an R data-frame r_patch containing the pxcor and pycor of patches and show that r_patch is a data-frame: (r:putagentdf "r_patch" patches "pxcor" "pycor") print r:get "class(r_patch)" |
putlist | Creates a new R list based on the submitted NetLogo variables and values. | ;; create an R list r_list containing the values of NetLogo list b: let b [12.95 10 11.3] r:putlist "r_list" b ;; create an R list r_list with three columns: (r:putlist "r_list" b [3 5] 4.5) print r:get "r_list[1]" |
putnamedlist | Same as putlist, but creates a named R list, i.e. the columns of the list can be called via their names. | ;; create a named R list r_list with three columns: (r:putnamedlist "r_list" "col1" b "col2" [3 5 2] "col3" 4.5) print r:get "r_list$col1" |
putdataframe | Same as putnamedlist, but creates an R data-frame instead of a list because many R functions require data frames as input. | ;; create an R data-frame r_df with 3 columns: (r:putdataframe "r_df" "col1" [4 2 5] "col2" [3 5 2] "col3" 4.5) print r:get "class(r_df)" |