0

I want to create an object in R, which will contain one string, with a few variables (in my case it is file path). When I try to use paste to concatenate the file paths I can see only one last variable instead of all variables in one string. I use next code:

for(i in seq_len(nrow(samples))) {
 lib = samples$conditions[i]
 txtFile = file.path(lib, "hits.txt")
 testfiles = paste(txtFile, sep = ',')
}
print(testfiles)

and get something like cond/hits.txt,

instead of cond/hits.txt,cond1/hits.txt,cond2/hits.txt and so on

Thank you very much for help

Tor
  • 1
  • 2
  • try `testfiles = paste(testfiles,txtFile, sep=",")` with `testfiles <- ""` before the `for` loop – aichao Jan 18 '17 at 16:59
  • Does `collapse = ","` instead of `sep = ","` do it? – cimentadaj Jan 18 '17 at 16:59
  • Thank you aichao and cimentadaj. it is strange, but when I use sep = ',' I get comma in a front of the string. When I use paste0 I get comma at the end of the string. What should I do to get the string with commas in the right places. – Tor Jan 18 '17 at 20:04
  • It would be a lot easier to help you if you posted a reproducible example. – ulfelder Jan 18 '17 at 20:31
  • @ulfelder for example, when I run the code below I'll get 1,2,3, I don't want the last comma to appear. Thank you very much. test = "" for(i in 1:3){ test = paste0( test, i, sep = ",")} print(test) By the way, why I cannot insert code with CTRL+K to the comment? – Tor Jan 20 '17 at 18:03

0 Answers0