Search code examples
rcsvexport-to-csvfilepath

When saving in R, what's the purpose of using "./" at the beginning of the file path?


I've searched for several days for an answer to this, and perhaps I'm not asking it the right way when I search, so I thought maybe someone here would have an answer.

I'm using windows 10. If I wanted to save a .csv file, for example, in my working directory, there are at least two ways I know of that the file path can be specified:

data(iris)
###save to a foler called Data in my working directory

#method 1
write.csv(iris, "./Data/iris.1.csv")

#method 2
write.csv(iris, "Data/iris.2.csv")

Both of these work and the file is identical in content and size.

Is there a difference between the two methods? I can't remember the specific instance, but I think I've had errors when using method 2 before, and solved it by using method 1. Do some file extensions or packages require the "./" at the beginning of the file path?


Solution

  • The "./" is called "dot-slash". In most cases, and with R in general, there isn't one, but it may be an older programming convention that is still sometimes used, or related to unix/linux/*ix filenames. There are a few answers in these posts that explain the difference.

    What does "./" (dot slash) refer to in terms of an HTML file path location?

    What is best practice use of dot slash?