After brief investigation, I've found the source of this problem myself. As I expected, it's really a simple and small mistake, which I will describe to prevent other people from bumping into similar things.
When I use file.exists()
in my code, I pass as parameter the relative path to the file in question. I construct that path by concatenating the hard-coded "cache" directory and the dynamically determined file name itself:
# calculate URL's digest and generate corresponding RData file name
fileDigest <- digest(url, algo="md5", serialize=F)
rdataFile <- paste(RDATA_DIR, "/", fileDigest, RDATA_EXT, sep = "")
However, I forgot that make
leaves the top-level project directory and enters the sub-directory to build the code and, thus, the hard-coded value of relative path to "cache" directory (RDATA_DIR="./cache"
) becomes incorrect. Simple change (RDATA_DIR="../cache"
) fixed the problem.
That explains the reason behind the "magic" :-), when the same code builds successfully manually (R or RStudio), but fails when building via make
. Having said that, I recognize that this might not be the best practice to rely on the predetermined directory structure, but due to time limits I have to decide on compromises (and add items to TODO [potential improvements] list). I will gladly listen to your advice on the best practices in this area.