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

Unexpected 'else' error when attempting to fit with uninstalled random forest engine #289

Closed
RichardPilbery opened this issue Apr 26, 2020 · 1 comment · Fixed by #293
Closed

Comments

@RichardPilbery
Copy link

The problem

When using parsnip v0.1.0 and attempting to fit a random forest model using ranger (which is not installed) an 'unexpected else' error appears.

Reproducible example

remove.packages('ranger')

library(modeldata)
data(cells, package = "modeldata")

library(parsnip)

rf_mod <- 
  rand_forest(trees = 1000) %>% 
  set_engine("ranger") %>%
  set_mode("classification")

set.seed(234)

rf_fit <- rf_mod %>% 
  fit(class ~ angle_ch_1, data = cells[cells$case == 'Train',])

# Error in parse(text = text, keep.source = FALSE) : 
#  <text>:5:5: unexpected 'else'
# 4:     }
# 5:     else
#       ^

Traceback output

20: parse(text = text, keep.source = FALSE)
19: eval(parse(text = text, keep.source = FALSE), envir)
18: .transformer(expr, env)
17: (function (expr) 
    {
        eval_func <- .transformer(expr, env)
        tryCatch(as.character(eval_func), error = function(e) {
            if (is.function(eval_func)) {
                message <- paste0("glue cannot interpolate functions into strings.\n", 
                    "* object '", expr, "' is a function.")
                stop(message, call. = FALSE)
            }
            stop(e)
        })
    })("\n    if (results$treetype == \"Probability estimation\") {\n        res <- colnames(results$predictions)[apply(results$predictions, 1, which.max)]\n    }\n    else {\n        res <- results$predictions\n    }\n    res\n")
16: glue_data(.x = NULL, ..., .sep = .sep, .envir = .envir, .open = .open, 
        .close = .close, .na = .na, .transformer = .transformer, 
        .trim = .trim)
15: glue::glue("This engine requires some package installs: ", glue::glue_collapse(glue::glue("'{x}'"), 
        sep = ", "))
14: is_null(msg)
13: validate_signal_message(message, class)
12: rlang::abort(glue::glue("This engine requires some package installs: ", 
        glue::glue_collapse(glue::glue("'{x}'"), sep = ", ")))
11: check_installs(object)
10: fit.model_spec(., class ~ angle_ch_1, data = cells[cells$case == 
        "Train", ])
9: fit(., class ~ angle_ch_1, data = cells[cells$case == "Train", 
       ])
8: function_list[[k]](value)
7: withVisible(function_list[[k]](value))
6: freduce(value, `_function_list`)
5: `_fseq`(`_lhs`)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
3: eval(quote(`_fseq`(`_lhs`)), env, env)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1: rf_mod %>% fit(class ~ angle_ch_1, data = cells[cells$case == 
       "Train", ])
@github-actions
Copy link

github-actions bot commented Mar 7, 2021

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant