Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug for check population and observation grouping NA #137

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions R/prepare_ae_specific.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,6 @@ prepare_ae_specific <- function(meta,
parameter,
components = c("soc", "par"),
reference_group = NULL) {
# Check if the grouping variable is missing
pop_grp <- vapply(meta$population, "[[", FUN.VALUE = character(1), "group")
obs_grp <- vapply(meta$population, "[[", FUN.VALUE = character(1), "group")
grp <- unique(c(pop_grp, obs_grp))

for (i in seq(grp)) {
if (any(is.na(meta$data_population[[grp[i]]]))) {
stop(
paste0(
"There are >= 1 subjects with missing grouping variable '", grp[i],
"' in the population dataset."
),
call. = FALSE
)
}
if (any(is.na(meta$data_observation[[grp[i]]]))) {
stop(
paste0(
"There are >= 1 subjects with missing grouping variable '", grp[i],
"' in the observation dataset."
),
call. = FALSE
)
}
}

# Obtain variables
pop_var <- collect_adam_mapping(meta, population)$var
obs_var <- collect_adam_mapping(meta, observation)$var
Expand All @@ -93,6 +67,31 @@ prepare_ae_specific <- function(meta,
pop_group <- collect_adam_mapping(meta, population)$group
obs_group <- collect_adam_mapping(meta, observation)$group

# Check if the grouping variable is missing
# pop_grp <- vapply(meta$population, "[[", FUN.VALUE = character(1), "group")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't have commented out code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't have commented out code.

I haved removed the code. Thanks for review!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nanxstats , since @wangben718 already removed the comments, I directly merged this PR to the master, considering there are two teammates who need the package for slide preparation early this week...

# obs_grp <- vapply(meta$population, "[[", FUN.VALUE = character(1), "group")
# grp <- unique(c(pop_grp, obs_grp))


if (any(is.na(pop[[pop_group]]))) {
stop(
paste0(
"There are >= 1 subjects with missing grouping variable '", pop_group,
"' in the population dataset."
),
call. = FALSE
)
}
if (any(is.na(obs[[obs_group]]))) {
stop(
paste0(
"There are >= 1 subjects with missing grouping variable '", obs_group,
"' in the observation dataset."
),
call. = FALSE
)
}

# Ensure group is a factor
if (!"factor" %in% class(pop[[pop_group]])) {
warning("In population level data, force group variable '", pop_group, "' be a factor")
Expand Down
26 changes: 0 additions & 26 deletions R/prepare_ae_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,6 @@ prepare_ae_summary <- function(meta,
observation,
parameter,
...) {
# Check if the grouping variable is missing
pop_grp <- vapply(meta$population, "[[", FUN.VALUE = character(1), "group")
obs_grp <- vapply(meta$population, "[[", FUN.VALUE = character(1), "group")
grp <- unique(c(pop_grp, obs_grp))

for (i in seq(grp)) {
if (any(is.na(meta$data_population[[grp[i]]]))) {
stop(
paste0(
"There are >= 1 subjects with missing grouping variable '", grp[i],
"' in the population dataset."
),
call. = FALSE
)
}
if (any(is.na(meta$data_observation[[grp[i]]]))) {
stop(
paste0(
"There are >= 1 subjects with missing grouping variable '", grp[i],
"' in the observation dataset."
),
call. = FALSE
)
}
}

parameters <- unlist(strsplit(parameter, ";"))

res <- lapply(parameters, function(x) {
Expand Down