0

I figured out how to read in my files a different why then I have been taught, but I had to use two // in stead of /, like I normally do. Can someone explain why do I need two // in r to vs one / in r to read a directory, while other times / works just fine?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Chad
  • 149
  • 4
  • 11
  • 4
    You statement is not correct, we need two "\" (escaping) and not two "/" http://stackoverflow.com/questions/14185287/escaping-in-string-or-paths-in-r – dickoa Dec 30 '13 at 16:58
  • @dickoa, my statement is correct: "/Users/chadhighfill/desktop/LongevityExperiment//longevityBlockTWO20132012//RILduplication//" – Chad Dec 30 '13 at 17:14
  • May be you're right but in 4 years of Linux and R I never had to double "/". Which OS are you using ? – dickoa Dec 30 '13 at 17:17
  • @ dickoa, I am using Mac and PC OS, but I do thank you for posting on the question. I am aspiring scientist that has to learning coding to look at my data, so coding isn't my strong suit. – Chad Dec 30 '13 at 17:21
  • I wish you all the best and Stackoverflow is really a great place to learn, there's also a lot of 'learning by doing' courses platform out there like datamind or codeschool – dickoa Dec 30 '13 at 17:25

1 Answers1

2

Look at these examples:

> data<-read.table('c:/test.txt')
> data<-read.table('c:\\test.txt')
> data<-read.table('c:\test.txt')
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'c:      est.txt': Invalid argument

See? If you use single '\', sometimes it gets confusing as in this case '\t' is the tab key. '\t' fixes this as double '\' is considered as the real '\' stuff.

But try save yourself some trouble to use '/', that is a good habit. (Seconded to @dickoa, I also suspect you actually meant '\' in the OP)

CT Zhu
  • 52,648
  • 17
  • 120
  • 133