The []
and [[]]
operators for linelist
objects behaves like for regular
data.frame
or tibble
, but check that tagged variables are not lost, and
takes the appropriate action if this is the case (warning, error, or ignore,
depending on the general option set via lost_tags_action()
) .
Usage
# S3 method for linelist
[(x, i, j, drop = FALSE)
# S3 method for linelist
[(x, i, j) <- value
# S3 method for linelist
[[(x, i, j) <- value
Arguments
- x
a
linelist
object- i
a vector of
integer
orlogical
to subset the rows of thelinelist
- j
a vector of
character
,integer
, orlogical
to subset the columns of thelinelist
- drop
a
logical
indicating if, when a single column is selected, thedata.frame
class should be dropped to return a simple vector, in which case thelinelist
class is lost as well; defaults toFALSE
- value
the replacement to be used for the entries identified in
x
See also
lost_tags_action()
to set the behaviour to adopt when tags are lost through subsetting; default is to issue a warningget_lost_tags_action()
to check the current the behaviour
Author
Thibaut Jombart thibaut@data.org
Examples
if (require(outbreaks) && require(dplyr) && require(magrittr)) {
## create a linelist
x <- measles_hagelloch_1861 %>%
tibble() %>%
make_linelist(
id = "case_ID",
date_onset = "date_of_prodrome",
age = "age",
gender = "gender"
) %>%
mutate(result = if_else(is.na(date_of_death), "survived", "died")) %>%
set_tags(outcome = "result") %>%
rename(identifier = case_ID)
x
## dangerous removal of a tagged column setting it to NULL issues a warning
x[, 1] <- NULL
x
x[[2]] <- NULL
x
}
#> Warning: The following tags have lost their variable:
#> id:identifier
#> Warning: The following tags have lost their variable:
#> date_onset:date_of_prodrome
#>
#> // linelist object
#> # A tibble: 188 × 11
#> infector date_of_rash date_of_death age gender family_ID class
#> <int> <date> <date> <dbl> <fct> <int> <fct>
#> 1 45 1861-11-25 NA 7 f 41 1
#> 2 45 1861-11-27 NA 6 f 41 1
#> 3 172 1861-12-02 NA 4 f 41 0
#> 4 180 1861-11-28 NA 13 m 61 2
#> 5 45 1861-11-27 NA 8 f 42 1
#> 6 180 1861-11-29 NA 12 m 42 2
#> 7 42 1861-11-28 NA 6 m 26 0
#> 8 45 1861-11-26 NA 10 m 44 1
#> 9 182 1861-11-30 NA 13 m 44 2
#> 10 45 1861-11-25 NA 7 f 29 1
#> # ℹ 178 more rows
#> # ℹ 4 more variables: complications <fct>, x_loc <dbl>, y_loc <dbl>,
#> # result <chr>
#>
#> // tags: gender:gender, age:age, outcome:result