Reputation: 10626
I am trying to see if file exists as follows:
linux.csv is like this
servera
serverb
serverc
serverd
server<-read.csv("C:/linux.csv")
setwd("\\\\share\directory\")
for (i in server) {
print(i)
}
i<-paste0(i,".sh")
if(!file.exists(i)){
print(i)
print(paste0(i, " does not exists"))
}
}
this does not seem to be working, any ideas?
Upvotes: 0
Views: 115
Reputation: 145775
read.csv
returns a data frame. When you do for (i in dataframe)
it will iterate over columns of the data frame, not rows. But
it looks like you have a single column with 4 rows, so that is the reason it isn't working.
I would suggest using readLines
instead of read.csv
, which will return a character vector. The rest of your code should work better then (though you seem to have an extra }
... be careful your for
loop doesn't end with a }
immediately after the first print()
statement).
Also, all backslashes in R strings need to be doubled, because they are escape characters. So setwd("\\\\share\directory\")
needs to be setwd("\\\\share\\directory\\")
. (Or use forward slashes instead.)
Upvotes: 2