Open SimonDedman opened 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
Similar issue if trying to workaround with cbind: Can name as string "col name" = 1:10, or
#or anything evaluated e.g. colnames(tmp)[2] = tmp[,2] error is unexpected = sign
Could use eval(parse(text(paste0 ? https://goodscienceblog.wordpress.com/2016/12/02/a-very-useful-function-eval-parse-text-paste/
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!