SimonDedman / gbm.auto

Machine-learning Boosted Regression Tree software suite for species distribution modelling in R
https://doi.org/10.1371/journal.pone.0188955
Other
18 stars 6 forks source link

Loop: csvs colnames for x are paste0'd wrongly #37

Open SimonDedman opened 6 years ago

SimonDedman commented 6 years ago

colnames are e.g.

Biom_SardAlec y get(paste0("gaustmp", k))[, 2] ...(nloops-1 of these, i.e. nloops with the y column) MinLine AvLine MaxLine VarLine

Same for bin as well as well as gaus? gbm.loop line 179 make construction simpler? Use tmp obvject name instead of assign then label column later e.g.

tmpcolname <- c(rep(NA, n), x[(1:len), i]) #create vec w/ n NAs @ front then variable minus n rows x <- cbind(x, tmpcolname) #bind that as the final column of x colno <- length(colnames(x)) #get that col number colnames(x)[colno] <- paste0(i, "lag", n) #name new col name_lag_n

Also tidy up file, remove dead comments!

SimonDedman commented 6 years ago

with or without get(): Error in colnames(paste0("gausline_", k))[i + 1] <- paste0("loop", i) : target of assignment expands to non-language object

But: colnames(get(paste0("Ann","ual")))[141] works: "HkFactor" but colnames(get(paste0("Ann","ual")))[141] <- "RENAMETEST" fails for the nonlanguage problem

Seems like it may be impossible without rewriting the whole function and having the objects within list(s) https://stackoverflow.com/questions/39148174/r-replacing-column-names-in-while-loop-with-changing-data-frame-names https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames https://stackoverflow.com/questions/27662162/error-in-my-code-target-of-assignment-expands-to-non-language-object and especially https://stackoverflow.com/questions/14464442/using-get-with-replacement-functions

SimonDedman commented 6 years ago

Similar issue if trying to workaround with cbind: Can name as string "col name" = 1:10, or

objectname ColName = 1:10 but not formulaicly paste0("Col","Name") = 1:10

      #or anything evaluated e.g. colnames(tmp)[2] = tmp[,2] error is unexpected = sign
SimonDedman commented 6 years ago

Could use eval(parse(text(paste0 ? https://goodscienceblog.wordpress.com/2016/12/02/a-very-useful-function-eval-parse-text-paste/