You can use closure_write()
to save the results of
closure_generate()
on your computer. A message will show the exact
location.
The data are saved in a new folder as four separate files, one for each
tibble in closure_generate()
's output. The folder is named after the
parameters of closure_generate()
.
closure_read()
is the opposite: it reads those files back into R,
recreating the original CLOSURE list. This is useful for later analyses if
you don't want to re-run a lengthy closure_generate()
call.
Arguments
- data
List returned by
closure_generate()
.- path
String (length 1). File path where
closure_write()
will create a new folder with the results. By default, the current working directory. Forclosure_read()
, the path to that new folder.
Details
closure_write()
saves the first three tibbles as CSVs, but the
"results"
tibble becomes a Parquet file. This is much faster and takes up
far less disk space — roughly 1% of a CSV file with the same data. Speed
and disk space can be relevant with large result sets.
Use closure_read()
to recreate the CLOSURE list from the folder. One of
the reasons why it is convenient is that opening a Parquet file requires a
special reader. For a more general tool, see
nanoparquet::read_parquet()
.
Folder name
The new folder's name should be sufficient to recreate its CLOSURE results. Dashes separate values, underscores replace decimal periods. For example:
CLOSURE-3_5-1_0-90-1-5-up_or_down-5
The order is the same as in closure_generate()
:
closure_generate(
mean = "3.5",
sd = "1.0",
n = 90,
scale_min = 1,
scale_max = 5,
rounding = "up_or_down", # default
threshold = 5 # default
)
Examples
data <- closure_generate(
mean = "2.7",
sd = "0.6",
n = 45,
scale_min = 1,
scale_max = 5
)
# Just for this example -- don't try at home
fake_folder <- tempdir()
# You should write to a real folder instead;
# or just leave `path` unspecified.
path_new_folder <- closure_write(data, path = fake_folder)
#> ✔ All files written to:
#> /tmp/Rtmptr0TYZ/CLOSURE-2_7-0_6-45-1-5-up_or_down-5/
# In a later session, conveniently read the files
# back into R. This returns the original list,
# identical except for floating-point error.
closure_read(path_new_folder)
#> $inputs
#> # A tibble: 1 × 7
#> mean sd n scale_min scale_max rounding threshold
#> <chr> <chr> <dbl> <dbl> <dbl> <chr> <dbl>
#> 1 2.7 0.6 45 1 5 up_or_down 5
#>
#> $metrics
#> # A tibble: 1 × 5
#> samples_initial samples_all values_all horns horns_uniform
#> <int> <int> <int> <dbl> <dbl>
#> 1 15 54 2430 0.0906 0.5
#>
#> $frequency
#> # A tibble: 5 × 4
#> value f_average f_absolute f_relative
#> <int> <dbl> <int> <dbl>
#> 1 1 1.37 74 0.0305
#> 2 2 12.7 685 0.282
#> 3 3 29.4 1585 0.652
#> 4 4 1.37 74 0.0305
#> 5 5 0.222 12 0.00494
#>
#> $results
#> # A tibble: 54 × 2
#> id sample
#> <int> <list>
#> 1 1 <int [45]>
#> 2 2 <int [45]>
#> 3 3 <int [45]>
#> 4 4 <int [45]>
#> 5 5 <int [45]>
#> 6 6 <int [45]>
#> 7 7 <int [45]>
#> 8 8 <int [45]>
#> 9 9 <int [45]>
#> 10 10 <int [45]>
#> # ℹ 44 more rows
#>