# simply import existing file
logo <- system.file("ex/logo.tif", package = "terra")
s <- ifMissing(logo)
# create nonexisting file and import it afterwards
logo2 <- file.path(tempdir(), "rlogo.tif")
s2 <- ifMissing(logo2, arg1 = "filename", x = s, datatype = "INT1U")
# this also works with text files and more sophisticated custom functions
fun = function(x, file = "", ...) {
write.csv(x, file, ...)
read.csv(file)
}
data(iris)
ofl <- file.path(tempdir(), "iris.csv")
iris2 <- ifMissing(ofl, fun1 = fun, x = iris, file = ofl, quote = FALSE, row.names = FALSE)
Run the code above in your browser using DataLab