minor fix for namespace not loading within "do.call"#358
Merged
gaow merged 1 commit intoStatFunGen:mainfrom Mar 17, 2025
Merged
minor fix for namespace not loading within "do.call"#358gaow merged 1 commit intoStatFunGen:mainfrom
gaow merged 1 commit intoStatFunGen:mainfrom
Conversation
| args_list$beta.init <- lasso_weights(X, y) | ||
| } | ||
| fit.mr.ash <- do.call("mr.ash.alpha::mr.ash", c(list(X = X, y = y, sa2 = if (init_prior_sd) init_prior_sd(X, y)^2 else NULL), args_list)) | ||
| fit.mr.ash <- mr.ash.alpha::mr.ash(X = X, y = y, sa2 = if (init_prior_sd) init_prior_sd(X, y)^2 else NULL, args_list) |
Collaborator
There was a problem hiding this comment.
If you can change:
args_list <- list(...)
to
args_list <- list2(...)
and then make this change
Suggested change
| fit.mr.ash <- mr.ash.alpha::mr.ash(X = X, y = y, sa2 = if (init_prior_sd) init_prior_sd(X, y)^2 else NULL, args_list) | |
| fit.mr.ash <- mr.ash.alpha::mr.ash(X = X, y = y, sa2 = if (init_prior_sd) init_prior_sd(X, y)^2 else NULL, !!!args_list) |
It should work for the arguments
I think you'll also then need:
#' @importFrom !!! rlang
#' @importFrom list2 rlang
in the roxygen comment.
Contributor
Author
There was a problem hiding this comment.
I tried with the updated function below
mrash_weights <- function(X, y, init_prior_sd = TRUE, ...) {
# Make sure mr.ash is installed
if (! requireNamespace("mr.ash.alpha", quietly = TRUE)) {
stop("To use this function, please install mr.ash: https://github.com/stephenslab/mr.ash.alpha")
}
args_list <- list2(...)
if (!"beta.init" %in% names(args_list)) {
args_list$beta.init <- lasso_weights(X, y)
}
fit.mr.ash <- mr.ash.alpha::mr.ash(X = X, y = y,
sa2 = if (init_prior_sd) init_prior_sd(X, y)^2 else NULL, !!!args_list)
predict(fit.mr.ash, type = "coefficients")[-1]
}
and I got error message of
Error in `map()`:
i In index: 5.
Caused by error in `!args_list`:
! invalid argument type
Traceback:
initially I thought it was because the step that adds additional list of $beta.init but got the same error by unlist with !!! and list2 again after adding beta.init
args_list$beta.init <- lasso_weights(X, y)
Contributor
Author
There was a problem hiding this comment.
I tried as below and it seemed to work, please advise
mrash_weights <- function(X, y, init_prior_sd = TRUE, ...) {
# Make sure mr.ash is installed
if (! requireNamespace("mr.ash.alpha", quietly = TRUE)) {
stop("To use this function, please install mr.ash: https://github.com/stephenslab/mr.ash.alpha")
}
args_list <- list2(...)
if (!"beta.init" %in% names(args_list)) {
args_list$beta.init <- lasso_weights(X, y)
}
fit.mr.ash <- do.call(getFromNamespace("mr.ash", "mr.ash.alpha"),
c(list(X = X, y = y, sa2 = if (init_prior_sd) init_prior_sd(X, y)^2 else NULL), args_list))
predict(fit.mr.ash, type = "coefficients")[-1]
}
Collaborator
There was a problem hiding this comment.
Okay that work around is actually fine, and you can switch list2 back to list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.