1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 21:42:01 +02:00

extend vctrs support

This commit is contained in:
2022-10-31 11:19:06 +01:00
parent 9444ed6d1d
commit 796b972f8a
6 changed files with 145 additions and 29 deletions

View File

@ -64,7 +64,10 @@ vec_ptype2.ab.character <- function(x, y, ...) {
y
}
vec_cast.character.ab <- function(x, to, ...) {
unclass(x)
as.character(x)
}
vec_cast.ab.character <- function(x, to, ...) {
return_after_integrity_check(x, "antimicrobial code", as.character(AMR_env$AB_lookup$ab))
}
# S3: mo
@ -75,7 +78,10 @@ vec_ptype2.mo.character <- function(x, y, ...) {
y
}
vec_cast.character.mo <- function(x, to, ...) {
unclass(x)
as.character(x)
}
vec_cast.mo.character <- function(x, to, ...) {
return_after_integrity_check(x, "microorganism code", as.character(AMR::microorganisms$mo))
}
# S3: disk
@ -88,15 +94,49 @@ vec_ptype2.disk.integer <- function(x, y, ...) {
vec_cast.integer.disk <- function(x, to, ...) {
unclass(x)
}
vec_cast.disk.integer <- function(x, to, ...) {
as.disk(x)
}
vec_cast.double.disk <- function(x, to, ...) {
unclass(x)
}
vec_cast.disk.double <- function(x, to, ...) {
as.disk(x)
}
vec_cast.character.disk <- function(x, to, ...) {
unclass(x)
}
vec_cast.disk.character <- function(x, to, ...) {
as.disk(x)
}
# S3: mic
vec_cast.character.mic <- function(x, to, ...) {
as.character(x)
}
vec_cast.double.mic <- function(x, to, ...) {
# this calls as.double.mic()
as.double(x)
}
vec_cast.mic.double <- function(x, to, ...) {
as.mic(x)
}
vec_cast.mic.character <- function(x, to, ...) {
as.mic(x)
}
vec_math.mic <- function(.fn, x, ...) {
.fn(as.double(x), ...)
}
# S3: rsi
vec_ptype2.character.rsi <- function(x, y, ...) {
x
}
vec_ptype2.rsi.character <- function(x, y, ...) {
y
}
vec_cast.character.rsi <- function(x, to, ...) {
as.character(x)
}
vec_cast.rsi.character <- function(x, to, ...) {
as.rsi(x)
}