This function creates reference codes by pasting name
, year
, yname
,
sex
and sub
fields. The result is a string that identifies the
reference.
make_refcode(name = "", year = "", yname = "", sex = "", sub = "")
A character vector with n
elements, where n
equals the longest
vector in the input arguments.
The function silently converts any zero-length arguments to length 1
.
The procedure aborts with an error if the length of any input is unequal to
either 1
or n
.
data <- data.frame(hgt = c(56, 42, 53),
age = c(0.1, 0.2, 0.15),
sex = c("male", "female", "female"),
ga = c(40, 27, 39))
r <- make_refcode("who", "2006", "hgt", data$sex)
r
#> [1] "who_2006_hgt_male_" "who_2006_hgt_female_" "who_2006_hgt_female_"
head(load_reference(r))
#> # A tibble: 6 × 4
#> x L M S
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0 1 49.9 0.0380
#> 2 0.0027 1 50.1 0.0378
#> 3 0.0055 1 50.2 0.0378
#> 4 0.0082 1 50.4 0.0376
#> 5 0.011 1 50.6 0.0375
#> 6 0.0137 1 50.8 0.0374
head(load_reference(r, "study"))
#> name year yname sex distribution citation
#> "who" "2006" "hgt" "male" "LMS" "WHO 2006"
head(load_reference(r[2]))
#> # A tibble: 6 × 4
#> x L M S
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0 1 49.1 0.0379
#> 2 0.0027 1 49.3 0.0378
#> 3 0.0055 1 49.5 0.0378
#> 4 0.0082 1 49.7 0.0377
#> 5 0.011 1 49.8 0.0376
#> 6 0.0137 1 50.0 0.0376
head(load_reference(r[2], "study"))
#> name year yname sex distribution citation
#> "who" "2006" "hgt" "female" "LMS" "WHO 2006"