user1574866
user1574866

Reputation: 275

Error when running R script

When I run my R script, it gives me an error:

Error in list.files(lib, pattern = paste0("^", pkg, "$"), full.names = TRUE) : 
  invalid 'pattern' regular expression

What does this error mean? the link to the script is: http://mzmatch.sourceforge.net/metabolomics/Processing_Code.R

But I changed few lines at the beginning:

library ("D:\\java projects\\RScriptRunning\\R\\win-library\\2.15\\mzmatch.R")
mzmatch.init (6000)
setwd ("D:\\R_Script\\raw")

Upvotes: 0

Views: 369

Answers (1)

MvG
MvG

Reputation: 60858

Completely rewrote my answer, as the first version missed the relevant point.

When you read an error message like this, a call to traceback() will tell you where the error occurred. In this case it will most likely identify the find.package function, which somehow got called from the library function. It constructs a path name from a package name, and does not escape the package name. So symbols which have a special meaning in regular expressions (likely the backslash) will render this regular expression invalid, thus the error message.

The reason is that you attempt to load a library using the full path name of one of its files. Libraries are loaded by package name only (most likely library(mzmatch) in your case). You can use source("C:\\some\\path") to load and execute R source code from a given path, but I'd not suggest doing so for an installed library.

Upvotes: 3

Related Questions