This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error: protect(): protection stack overflow

Hi,

I am trying to do random forest analysis for microbiome data in R but I am getting below error , could you please suggest how I can resolve it?

set.seed(123)
#run random forest
physeq.DNA.Close_5_Filtered_Classify <- randomForest(response~., data = rf.data, ntree = 200)
Error: protect(): protection stack overflow

Many thanks,
bioinfonext

r random-forest

Looks like this is a memory issue. Can you assign more memory to R (or Rstudio if that is what you are using)?

I am working on iMac R terminal and try to use below codes but not resolved the issue.

Step 1: Open terminal,

Step 2:

cd ~
touch .Renviron
open .Renviron
Step 3: Save the following as the first line of .Renviron:

R_MAX_VSIZE=100Gb 
Note: This limit includes both physical and virtual memory; so setting _MAX_VSIZE=16Gb on a machine with 16Gb of physical memory may not prevent this error. You may have to play with this parameter, depending on the specs of your machine

Many thanks

I also tried this;

env R_MAX_VSIZE=700Gb R

but still getting same error!

  > gc()
         used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
Ncells 267317 14.3     642811 34.4         NA   442668 23.7
Vcells 544293  4.2    8388608 64.0      32768  1770323 13.6
> sessionInfo()
R version 3.6.0 (2019-04-26)

What is the size of the data file you are trying to use? While virtual memory can help in some instances it may not be able to avoid limitations of actual RAM you have available.

file.info(Rf.data.txt")
              size isdir mode               mtime               ctime
Rf.data.txt 7951144 FALSE  644 2020-10-15 19:41:38 2020-10-15 19:41:38
                         atime uid gid  uname grname

1 answer

This was asked a long time ago, but maybe someone looking for an answer won't see the non-bioinformatics boards.

The formula syntax might be causing the problem. Try again using:

physeq.DNA.Close_5_Filtered_Classify <- randomForest(x = rf.data[ , colnames(rf.data) != "response"], 
                                                     y = rf.data$response, ntree = 200)

Hi, I was having the same error "Error: protect(): protection stack overflow" in my code below.

xgb_train <- train( as.formula(paste(target, "~ .")), data = train_data, method = "xgbTree", trControl = ctrl, tuneGrid = hyper_grid, verbose = FALSE, verbosity = 0, metric = "RMSE" )

But I changed to the below given code it worked.

xgb_train <- train( train_data, label, method = "xgbTree", trControl = ctrl, tuneGrid = hyper_grid, verbose = FALSE, verbosity = 0, metric = "RMSE" )

So, the error is because of formula syntax you are using. Enjoy :)

Log in to answer this question.