-
Notifications
You must be signed in to change notification settings - Fork 2
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
error when variable names have partial matching #34
Comments
I am not a great expert of the regular expressions. But it seems that also the "_" in the variable name makes it complicate to adapt the grep-pattern... The following function works, but maybe it's a bit messy: # the following command is now working
plot_gam(model = fit_gam_test, pred = "^x_0$")
# with...
gam_to_df <- function (model = NULL, pred = NULL)
{
plot_df <- no_plot(model)
# grep all names first
plot_df_names <- sapply(plot_df, function(x) x$xlab) %>%
gsub(pattern = "_", replacement = "", x = .)
# gsub possible bad characters in names (could be extended when further error occurs)
pred <- gsub(pattern = "_", replacement = "", x = pred)
set_pred <- which(grepl(pred, plot_df_names)) # switch plot_df with plot_df_names
df <- data.frame(x = plot_df[[set_pred]]$x, se_upr = plot_df[[set_pred]]$fit +
plot_df[[set_pred]]$se, se_lwr = plot_df[[set_pred]]$fit -
plot_df[[set_pred]]$se, y = plot_df[[set_pred]]$fit)
return(df)
} |
Hi @raff-k, thanks for reporting. If its just a Do you have time to do this? |
Note that |
Hello, I would like to use your functions to display GAMs smoothing function. Some of my variables have partial matching variable names such as "slp" and "slp_catch". It seems, that this causes an error inside your function. Here a reproducible example.
The text was updated successfully, but these errors were encountered: