So today, I found myself in an interesting situation wherein I was writing out an R object to disk, but needed to keep the file’s name and path in session so I could do something with it later. Typically, doing that would look like this:
# first, make some data, to write to diskmydat <-data(iris) fname <-"iris.csv"write.csv(x = mydat, fname)# do some coding# do some coding# do some coding# later on, reference the file using the fname variablefile.exists(fname)
[1] TRUE
file.remove(fname)
[1] TRUE
For some, this might be perfectly fine, but I found another interesting way of doing this using magrittr’s “Tee” pipe (%T>%):