Method for tibble::as_tibble(): the same table as as_table(), returned
as a tibble, so that as_tibble(x) and x |> as_tibble() work in tidyverse
workflows. All arguments of as_table() are available, including table
for the length (HL) and individual (CA) data.
Arguments
- x
A
datras_rawobject.- ...
Passed to
tibble::as_tibble()for the converted table, e.g..name_repair.- vars
Character vector of
HHvariable names to include. Defaults to 15 common haul-level columns:Survey,Gear,Country,Ship,Year,Quarter,Month,Day,lon,lat,timeOfYear,abstime,DayNight,TimeShotHour,HaulDur.- add_vars
Character vector of additional
HHvariable names to append tovars. Applied afterremove_vars.- remove_vars
Character vector of variable names to drop from
vars. Applied beforeadd_vars.- type
Character string specifying the output format:
"long"(default) or"wide". See Details for what each means pertable.- table
Character string naming the table to export:
"HH"(default) for one row per haul,"HL"for numbers at length by haul and species, or"CA"for one row per individual record.- hl_by
Character vector of
HLcolumns that define a row fortable = "HL", in addition to the haul. Defaultc("Valid_Aphia", "LngtCm"): species x length class, summed over sex and catch category. Add"Sex"to keep sexes apart. Must contain"Valid_Aphia".- zeros
Logical. For
table = "HL": ifTRUE(default), add a row withCount = 0for every haul inHHand species inHLwithout a record, so that averages over hauls include the hauls where a species was not caught.- ca_vars
Character vector of
CAcolumns to include fortable = "CA". Columns not found are omitted with a warning.
Value
A tibble. See as_table() for the rows and columns of each
table and type.
Details
The method is registered when the tibble package is installed; tibble is not required otherwise.
Examples
if (requireNamespace("tibble", quietly = TRUE)) {
dab <- add_numbers_at_length(dab)
dab <- add_total_numbers_by_haul(dab, length_cuts = c(0, 20, Inf))
tibble::as_tibble(dab)
tibble::as_tibble(dab, type = "wide", add_vars = "Depth")
tibble::as_tibble(dab, table = "HL", vars = c("Year", "lon", "lat"))
}
#> Warning: Mixed accuracies found in var[[3]]$LngtCode - worst chosen: 1 cm
#> Warning: NAs found in var[[3]]$LngtCode - assumed to be 1 cm
#> # A tibble: 25,596 × 8
#> haul.id Year lon lat Valid_Aphia LngtCm Species Count
#> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <fct> <dbl>
#> 1 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 12 Limand… 6.34
#> 2 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 13 Limand… 4.22
#> 3 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 14 Limand… 4.22
#> 4 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 15 Limand… 4.22
#> 5 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 16 Limand… 2.11
#> 6 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 17 Limand… 6.34
#> 7 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 18 Limand… 21.1
#> 8 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 19 Limand… 21.1
#> 9 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 20 Limand… 27.5
#> 10 NS-IBTS:2020:1:DK:26D4:GO… 2020 7.14 56.6 127139 21 Limand… 21.1
#> # ℹ 25,586 more rows
