Skip to content

Commit

Permalink
update utils
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu committed Mar 26, 2024
1 parent 5c89ae1 commit ddbeb9f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,21 @@ apply_metadata <- function(df, filename, add_adsl = TRUE, adsl_filename = "metad
}

if (type == "character" && !is.character(df[[var]])) {
df[[var]] <<- as.character(df[[var]])
df[[var]] <- as.character(df[[var]])
} else if (type == "factor" && !is.factor(df[[var]])) {
df[[var]] <<- as.factor(df[[var]])
df[[var]] <- as.factor(df[[var]])
} else if (type == "integer" && !is.integer(df[[var]])) {
df[[var]] <<- as.integer(df[[var]])
df[[var]] <- as.integer(df[[var]])
} else if (type == "numeric" && !is.numeric(df[[var]])) {
df[[var]] <<- as.numeric(df[[var]])
df[[var]] <- as.numeric(df[[var]])
} else if (type == "logical" && !is.logical(df[[var]])) {
df[[var]] <<- as.logical(df[[var]])
df[[var]] <- as.logical(df[[var]])
} else if (type == "datetime" && !lubridate::is.POSIXct(df[[var]])) {
df[[var]] <<- as.POSIXct(df[[var]])
df[[var]] <- as.POSIXct(df[[var]])
} else if (type == "date" && !lubridate::is.Date(df[[var]])) {
df[[var]] <<- as.Date(df[[var]])
df[[var]] <- as.Date(df[[var]])
}
return(df)
}

# remove existing attributes
Expand Down Expand Up @@ -307,7 +308,7 @@ apply_metadata <- function(df, filename, add_adsl = TRUE, adsl_filename = "metad

# assign labels to variables
for (var in metadata_varnames) {
apply_type(df, var, metadata_variables[[var]]$type)
df <- apply_type(df, var, metadata_variables[[var]]$type)
attr(df[[var]], "label") <- metadata_variables[[var]]$label
}

Expand Down

0 comments on commit ddbeb9f

Please sign in to comment.