lokheart
lokheart

Reputation: 24675

how to list a portion of objects in R?

I want to list all objects in R that start with something, like starts with character "A", I only know how to use ls(), is there a way to do so? Thanks!

Upvotes: 4

Views: 125

Answers (1)

Vince
Vince

Reputation: 7638

ls() has a pattern argument - see ?ls. To search with an 'a' anywhere:

> ls(pattern='a')
[1] "a"              "clean"          "extractRawText" "extractRSS"     "extractText"    "parts"          "raw.data"    

Or with a regular expression to get things that start with "A":

> ls(pattern='^A')
[1] "A"   "Act"

If you don't know about regular expressions, but know about wildcards like '*' and such, you can use glob2rx():

> ls(pattern=glob2rx("A*"))
[1] "A"   "Act"

Upvotes: 5

Related Questions