r - Import files using key words -
i import image files using parts of names. have 100 .tif images names composed of 3 different elements, ai, bi , ci in such way: "a1 b1 c1.tif", "a1 b2 c1.tif", "a1 b1 c2.tif", "a2 b1 c1.tif"... defined ai, bi , ci @ beginning of code, , want call file contains these 3 elements.
i have tried options have no chance correct, cannot find better:
f = readtiff(ai bi ci) f = readtiff(ai, bi, ci) f = readtiff("ai bi ci")
and same using readimage , file.name. getwd gives correct path. thank in advance.
you can use paste
command glue strings together.
# for a, j b selection , k c selection my.filename <- paste("a", i, " b", j, " c", k, ".tif", sep = "")
so if wanted import a1 b2 c2.tif
i <- 1 j <- 2 k <- 2 my.filename <- paste("a", i, " b", j, " c", k, ".tif", sep = "")
note paste0 defaults sep = "" paste0("a", i, " b", j, " c", k, ".tif")
results in my.filename
1) "a1 b2 c2.tif"
if working paths then:
my.filename <- paste("a", i, " b", j, " c", k, ".tif", sep = "") my.path <- getwd() # or set readtiff(file.path(my.path, my.filename))
if want work through combinations of i, j, k in loops can use file.exists
, if import it.
note: package using readtiff
? not forget make sure package loaded in script, library(thispackage)
if getting "object not found" errors.
Comments
Post a Comment