read_experiment() reads NetLogo
BehaviorSpace
experiment output files as
tidy data frames.
It automatically detects the output format
(Table,
Spreadsheet,
Lists, or
Stats)
and parses the data accordingly. The function also extracts metadata from
the files.
Only version 2.0 (NetLogo 6.4 and later) of BehaviorSpace output files is supported.
Arguments
- file
A
characterstring specifying the path to the BehaviorSpace output CSV file.- tidy_output
(optional) A
logicalflag indicating whether to tidy the output data frames. IfTRUE, output data frames are arranged according to tidy data principles. IfFALSE, only the default transformations fromread_delim()andclean_names()are applied to the output data (default:TRUE).
Value
A list containing the experiment results. The list
includes the following elements, depending on the output file provided:
metadata: Alistwith metadata about the experiment run (present in all cases).spreadsheet: Alistwith the results of thespreadsheetoutput containing two elements:statistics: Atibblewith the results of thestatisticsoutput.
See also
Other BehaviorSpace functions:
create_experiment(),
inspect_experiment(),
run_experiment()
Examples
file <- tempfile()
c(
'BehaviorSpace results (NetLogo 7.0.3), "Table version 2.0"',
paste0(
'"/opt/NetLogo 7-0-3/models/',
'IABM Textbook/chapter 4/Wolf Sheep Simple 5.nlogox"'
),
'"Wolf Sheep Simple Model Analysis"',
'"01/05/2026 06:37:48:683 -0300"',
'"min-pxcor","max-pxcor","min-pycor","max-pycor"',
'"-17","17","-17","17"',
paste0(
'"[run number]","number-of-sheep","number-of-wolves",',
'"movement-cost","grass-regrowth-rate","energy-gain-from-grass",',
'"energy-gain-from-sheep","[step]","count wolves","count sheep"'
),
'"3","500","5","0.5","0.3","2","5","0","5","500"',
'"5","500","5","0.5","0.3","2","5","0","5","500"',
'"4","500","5","0.5","0.3","2","5","0","5","500"',
'"6","500","5","0.5","0.3","2","5","0","5","500"',
'"1","500","5","0.5","0.3","2","5","0","5","500"',
'"8","500","5","0.5","0.3","2","5","0","5","500"',
'"9","500","5","0.5","0.3","2","5","0","5","500"',
'"2","500","5","0.5","0.3","2","5","0","5","500"'
) |>
writeLines(file)
read_experiment(file)
#> $metadata
#> $metadata$timestamp
#> [1] "2026-01-05 09:37:48 -03"
#>
#> $metadata$netlogo_version
#> [1] "7.0.3"
#>
#> $metadata$output_version
#> [1] "2.0"
#>
#> $metadata$model_file
#> [1] "Wolf Sheep Simple 5.nlogox"
#>
#> $metadata$experiment_name
#> [1] "Wolf Sheep Simple Model Analysis"
#>
#> $metadata$world_dimensions
#> min-pxcor max-pxcor min-pycor max-pycor
#> -17 17 -17 17
#>
#>
#> $table
#> # A tibble: 8 × 10
#> run_number number_of_sheep number_of_wolves movement_cost grass_regrowth_rate
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 500 5 0.5 0.3
#> 2 2 500 5 0.5 0.3
#> 3 3 500 5 0.5 0.3
#> 4 4 500 5 0.5 0.3
#> 5 5 500 5 0.5 0.3
#> 6 6 500 5 0.5 0.3
#> 7 8 500 5 0.5 0.3
#> 8 9 500 5 0.5 0.3
#> # ℹ 5 more variables: energy_gain_from_grass <dbl>,
#> # energy_gain_from_sheep <dbl>, step <dbl>, count_wolves <dbl>,
#> # count_sheep <dbl>
#>