Skip to contents

Removes the class cacs_run_result from a result of cacs_run(), so that the table prints as an ordinary tibble, and keeps the other attributes. The rows keep their order in x unless rate_first is TRUE; the rows are then sorted by site_id, drive_time_min, and variable, with the rows of the five rates before the other rows within each site and drive time.

Usage

# S3 method for class 'cacs_run_result'
as_tibble(x, ..., rate_first = NULL)

Arguments

x

A cacs_run_result object, as returned by cacs_run().

...

Passed to the data frame method of tibble::as_tibble(), such as .name_repair.

rate_first

A logical value: TRUE puts the rate rows first and FALSE keeps the order of the rows. With NULL (the default), the option catchmentACS.rate_first_default, FALSE unless it has been set, decides in the calls described above, and other calls keep the order. A result without a variable column, such as the list-column form, keeps its order either way.

Value

A tibble of class c("tbl_df", "tbl", "data.frame") with the rows, columns, and attributes of x.

Details

With rate_first = NULL (the default), the option catchmentACS.rate_first_default decides, but only when as_tibble() is called from code run in the global environment, such as the console, a script, a document, or a function written in one of them. A conversion made inside another package, such as dplyr, keeps the order, and so does a call that passes the function itself, as in lapply(results, tibble::as_tibble). The first time the option puts the rate rows first in an R session, a message says so.

Examples

out <- readRDS(system.file("extdata", "visual_walkthrough_fixture.rds",
                           package = "catchmentACS"))$run_result

# By default the rows keep their order in out: the 14 ACS variables, then
# the five rates
tibble::as_tibble(out)$variable
#>  [1] "B01003_001"                "B11001_001"               
#>  [3] "B17001_001"                "B17001_002"               
#>  [5] "B19013_001"                "B19056_001"               
#>  [7] "B19056_002"                "B19301_001"               
#>  [9] "B22003_001"                "B22003_002"               
#> [11] "B23025_001"                "B23025_002"               
#> [13] "B23025_003"                "B23025_005"               
#> [15] "poverty_rate"              "snap_rate"                
#> [17] "ssi_rate"                  "unemp_rate"               
#> [19] "labor_force_participation"

# The rates first
tibble::as_tibble(out, rate_first = TRUE)$variable
#>  [1] "labor_force_participation" "poverty_rate"             
#>  [3] "snap_rate"                 "ssi_rate"                 
#>  [5] "unemp_rate"                "B01003_001"               
#>  [7] "B11001_001"                "B17001_001"               
#>  [9] "B17001_002"                "B19013_001"               
#> [11] "B19056_001"                "B19056_002"               
#> [13] "B19301_001"                "B22003_001"               
#> [15] "B22003_002"                "B23025_001"               
#> [17] "B23025_002"                "B23025_003"               
#> [19] "B23025_005"