I have a function doing a for loop that:
#1) reads the first element in dir
#2) does some calculation
#3) asks for user input using select.list(...,graphics=T)
#4) checks several until user confirms that the chosen variables are correct
#5) does some more calculation
#6) goes to the next element in dir and repeats everything.
The loop works great and fast (the reading calculations are very soft). Moreover, people with zero coding experience use the function in a flexible way without problem (that was my original intention when coding it this way). But if I wanted to select all the same variables for all the files (do batch processing of 1000 files) it gets annoying to click every single time and reconfirm writing 'yes'.
I'm looking for an argument to add that will allow me to bypass the while control structure providing the variables just one time
if batch.mode==T I should be able to read and subset all the files using the same variables without having to redefine for each iteration.
function(...,batch.mode=F){
for (i in dir(){
# do calculations
# previous code makes 'lista' being a list of data and we want to select within the names of that to subset later
# I used this code for making that selection 'user friendly'
x=1
while(x<2) {
myvars=select.list(names(lista),multiple=TRUE,
title='Hold Ctrl and click to select variables',
graphics=TRUE)
my_text_vars=paste0(myvars,'-',collapse = '')
ask=readline(paste0('Are ',my_text_vars,' ALL your variables (Yes/No)? :>'))
if(tolower(ask) == 'yes') { x=x+2
} else {
print('Please select again.')
x = x + 0.1
if (x>1.5) stop('Please run whole function again')
next()
}}
# calculations continue using myvars to subset
# table gets written
}
}
Aucun commentaire:
Enregistrer un commentaire