Skip to content
Prev 358247 / 398498 Next

Basic Problem with Data Input

Hi,

Using the full path specification, as you have done in your second example, is a good idea.   Have you tried forward slashes?  If I am reading the docs correctly you should be able to use either forward or back slashes.  I haven't used R in Windows for ages, but my memory is that switching to forward slashes skirted any troublesome issues.  Try this...

filename <- "C:/Program Files/R/R-3.2.3/Appendix/DATA1.txt"
if (file.exists(filename)){
	X <- scan(file = filename, what = double())
} else {
	cat('file not found\n')
}

Here's the doc page...

https://cran.r-project.org/doc/manuals/r-release/R-intro.html#OS-facilities

Ben
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org