Skip to content

Commit

Permalink
casting for factors
Browse files Browse the repository at this point in the history
  • Loading branch information
emitanaka committed Nov 26, 2023
1 parent 790f593 commit 5afbe8c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ S3method(vec_cast,edbl_fct.character)
S3method(vec_cast,edbl_rcrd.character)
S3method(vec_cast,edbl_rcrd.double)
S3method(vec_cast,edbl_rcrd.edbl_rcrd)
S3method(vec_cast,edbl_rcrd.factor)
S3method(vec_cast,edbl_rcrd.integer)
S3method(vec_cast,edbl_trt.character)
S3method(vec_cast,edbl_trt.double)
S3method(vec_cast,edbl_trt.edbl_trt)
S3method(vec_cast,edbl_trt.factor)
S3method(vec_cast,edbl_trt.integer)
S3method(vec_cast,edbl_unit.character)
S3method(vec_cast,edbl_unit.double)
S3method(vec_cast,edbl_unit.edbl_unit)
S3method(vec_cast,edbl_unit.factor)
S3method(vec_cast,edbl_unit.integer)
S3method(vec_cast,factor.edbl_rcrd)
S3method(vec_cast,factor.edbl_trt)
S3method(vec_cast,factor.edbl_unit)
S3method(vec_cast,integer.edbl_rcrd)
S3method(vec_cast,integer.edbl_trt)
S3method(vec_cast,integer.edbl_unit)
Expand All @@ -73,6 +79,7 @@ S3method(vec_ptype2,double.edbl_unit)
S3method(vec_ptype2,edbl_rcrd.character)
S3method(vec_ptype2,edbl_rcrd.double)
S3method(vec_ptype2,edbl_rcrd.edbl_rcrd)
S3method(vec_ptype2,edbl_rcrd.factor)
S3method(vec_ptype2,edbl_rcrd.integer)
S3method(vec_ptype2,edbl_trt.character)
S3method(vec_ptype2,edbl_trt.double)
Expand All @@ -82,6 +89,7 @@ S3method(vec_ptype2,edbl_unit.character)
S3method(vec_ptype2,edbl_unit.double)
S3method(vec_ptype2,edbl_unit.edbl_unit)
S3method(vec_ptype2,edbl_unit.integer)
S3method(vec_ptype2,factor.edbl_rcrd)
S3method(vec_ptype2,integer.edbl_rcrd)
S3method(vec_ptype2,integer.edbl_trt)
S3method(vec_ptype2,integer.edbl_unit)
Expand Down
16 changes: 16 additions & 0 deletions R/fcts.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ vec_ptype2.integer.edbl_trt <- function(x, y, ...) x
#' @export
vec_ptype2.edbl_trt.edbl_trt <- function(x, y, ...) x

#' @export
vec_ptype2.edbl_rcrd.factor <- function(x, y, ...) y
#' @export
vec_ptype2.factor.edbl_rcrd <- function(x, y, ...) x
#' @export
vec_ptype2.edbl_rcrd.character <- function(x, y, ...) y
#' @export
Expand All @@ -211,6 +215,10 @@ vec_cast.edbl_trt.integer <- function(x, to, ...) x
#' @export
vec_cast.integer.edbl_trt <- function(x, to, ...) as.integer(unclass(x))
#' @export
vec_cast.edbl_trt.factor <- function(x, to, ...) x
#' @export
vec_cast.factor.edbl_trt <- function(x, to, ...) as.factor(unclass(x))
#' @export
vec_cast.edbl_trt.character <- function(x, to, ...) x
#' @export
vec_cast.character.edbl_trt <- function(x, to, ...) as.character(unclass(x))
Expand All @@ -226,6 +234,10 @@ vec_cast.edbl_unit.integer <- function(x, to, ...) x
#' @export
vec_cast.integer.edbl_unit <- function(x, to, ...) as.integer(unclass(x))
#' @export
vec_cast.edbl_unit.factor <- function(x, to, ...) x
#' @export
vec_cast.factor.edbl_unit <- function(x, to, ...) as.factor(unclass(x))
#' @export
vec_cast.edbl_unit.character <- function(x, to, ...) x
#' @export
vec_cast.character.edbl_unit <- function(x, to, ...) as.character(unclass(x))
Expand All @@ -241,6 +253,10 @@ vec_cast.edbl_rcrd.integer <- function(x, to, ...) x
#' @export
vec_cast.integer.edbl_rcrd <- function(x, to, ...) as.integer(unclass(x))
#' @export
vec_cast.edbl_rcrd.factor <- function(x, to, ...) x
#' @export
vec_cast.factor.edbl_rcrd <- function(x, to, ...) as.factor(unclass(x))
#' @export
vec_cast.edbl_rcrd.character <- function(x, to, ...) x
#' @export
vec_cast.character.edbl_rcrd <- function(x, to, ...) as.character(unclass(x))
Expand Down
2 changes: 1 addition & 1 deletion R/simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ get_censored_value <- function(y, valid, censor) {
} else {
y[!ind] <- censor
}
y
factor(y, levels = valid$values)
} else if(type=="integer") {
valid$record <- "numeric"
res <- get_censored_value(y, valid, censor)
Expand Down

0 comments on commit 5afbe8c

Please sign in to comment.