[R] source() fails in same directory as script: cannot find file

Rich Shepard r@hep@rd @ending from @ppl-eco@y@@com
Fri Oct 26 18:30:22 CEST 2018


   I'm not seeing my error even after reading ?source and a couple of web
fora threads. Running R-3.5.1 on Slackware-14.2.

   The scripts/ directory has the file 'input-summarize.R' with these lines:

sites <- read.table('../data/stations.dat', header=T, sep=',', stringsAsFactors=T)
sink('../analyses/location-summaries.txt')
print(summary(sites)
sink(NULL)

hg_conc <- read.table('../data/concentrations.dat', header=T, sep=',', stringsAsFactors=T)
hg_conc$sampdate <- as.Date(as.character(hg_conc$sampdate))
sink('../analyses/concentration-summaries.txt')
print(summary(hg_conc)
sink(NULL)

   Sourcing the script within the same directory (confirmed using getwd())
fails with this error message:

> source('input-summarize.R')
Error in file(filename, "r", encoding = encoding) :
   cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
   cannot open file 'input-summarize.R': No such file or directory

   I've used this same syntax to source scripts within the past month and
would like to understand this error so I can fix it now and avoid it in the
future.

TIA,

Rich



More information about the R-help mailing list