I already referred this post and this post. But it doesn't solve my problem. Please don't mark it as duplicate
I am trying to run the below piece of code in Jupyter Notebook
with R kernel
.
model_predictors <- buildModel(flag, fv_full_data, outcomeName, folder)
I get an error message like below
Model about to be built # this is log message and not error
1 package is needed for this model and is not installed. (randomForest). Would you like to try to install it now? # here I see that it asks for a question but without my input it selects `No`
Error: Required package is missing
Traceback:
1. buildModel(flag, fv_full_data, outcomeName, folder)
2. train(x = trainDF[, predictorsNames], y = factor(trainLabels),
. method = "rf", metric = "Fscore", trControl = objControl,
. tuneGrid = rf_grid, preProcess = c("center", "scale"))
3. train.default(x = trainDF[, predictorsNames], y = factor(trainLabels),
. method = "rf", metric = "Fscore", trControl = objControl,
. tuneGrid = rf_grid, preProcess = c("center", "scale"))
4. checkInstall(models$library)
5. stop("Required package is missing", call. = FALSE)
How can I avoid this error and prevent jupyter selecting No
as default for dynamic prompts?
In your example, you actually never reach the part of code that handles input. These inputs only occur for interactive sessions - which Jupyter is not. You can check with
caret::checkInstall
prints out the message "Would you like to try to install x now?", but it will only accept input for interactive sessions.Here is the code for
caret::checkInstall
with my comments.For your situation,
install.packages("randomForest")
is the best option.If you were in
RStudio
, you could use therstudioapi
like this