2

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?

E. Moore
  • 321
  • 1
  • 5
  • 11
  • 1
    i believe the `.`means the path of the current working directory, set by `setwd()` (or de project's default wd) – Wimpel Mar 10 '21 at 19:19
  • 1
    on windows / r studio, you will get away with not using the `./`, but in other work environments you *might* not. I believe it is best practice to just use `./`. – Wimpel Mar 10 '21 at 19:23

1 Answers1

1

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?