0

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")
2
  • Could you please show the code used that causes this error, not just the message? (In particular, we need to see what is in pkg) Commented Aug 11, 2012 at 19:59
  • 2
    we need a reproducible example please ... this question can't be answered without any context. See tinyurl.com/reproducible-000 . In particular, the error means that the pkg variable contained a string that doesn't make a legitimate regular expression (see ?regexp), but we can't really say much without context. Commented Aug 11, 2012 at 20:00

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

The problem could be in the "mzmatch.R" package used in the script.
As someone downvoted this answer, I'd be happy to see a comment informing me and others about the reason for that vote.
The downvote might have been related to what Joshua Ulrich mentioned - before you edited the post you were only assuming that the error was in the code and that the user would need to change something in the gsub - but it was most likely due to a call to a function in the package used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.