What command lists everything in a package?

9 messages Options
Embed this post
Permalink
Mark Knecht

What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
Hi,
   Two easy questions I'm sure.

1) As an example if I use the code

require(zoo)

then once it's loaded is there a command that lists everything that
zoo provides so that I can study the package?

   Certainly help(zoo) gives me some clues about what zoo does but I'd
like a list. Maybe there's a way to query something but in Rgui under
Win Vista ls() returns nothing after zoo is loaded.

2) Related to the above, how do I tell what packages are currently
loaded at any given time so that I don't waste time loading things
that are already loaded? search() tells me what's available, but
what's loaded? The best I can find so far goes like this:

> a<-.packages(all.available = FALSE)
> a
[1] "zoo"       "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "methods"   "base"
>

Maybe that's as good as it gets in code and if I want better then I
write a function?

Thanks,
Mark

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Gabor Grothendieck

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
library(help = zoo)

will list all the help files and, at the bottom, all the vignettes.
It does not list demos so to get those you have to issue a
second command:

demo(package = "zoo")

On Fri, Jul 3, 2009 at 1:21 PM, Mark Knecht<[hidden email]> wrote:

> Hi,
>   Two easy questions I'm sure.
>
> 1) As an example if I use the code
>
> require(zoo)
>
> then once it's loaded is there a command that lists everything that
> zoo provides so that I can study the package?
>
>   Certainly help(zoo) gives me some clues about what zoo does but I'd
> like a list. Maybe there's a way to query something but in Rgui under
> Win Vista ls() returns nothing after zoo is loaded.
>
> 2) Related to the above, how do I tell what packages are currently
> loaded at any given time so that I don't waste time loading things
> that are already loaded? search() tells me what's available, but
> what's loaded? The best I can find so far goes like this:
>
>> a<-.packages(all.available = FALSE)
>> a
> [1] "zoo"       "stats"     "graphics"  "grDevices" "utils"     "datasets"
> [7] "methods"   "base"
>>
>
> Maybe that's as good as it gets in code and if I want better then I
> write a function?
>
> Thanks,
> Mark
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Henrique Dallazuanna

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Mark Knecht
To see all functions in a package:

library(zoo)
ls("package:zoo")

On Fri, Jul 3, 2009 at 2:21 PM, Mark Knecht <[hidden email]> wrote:

> Hi,
>   Two easy questions I'm sure.
>
> 1) As an example if I use the code
>
> require(zoo)
>
> then once it's loaded is there a command that lists everything that
> zoo provides so that I can study the package?
>
>   Certainly help(zoo) gives me some clues about what zoo does but I'd
> like a list. Maybe there's a way to query something but in Rgui under
> Win Vista ls() returns nothing after zoo is loaded.
>
> 2) Related to the above, how do I tell what packages are currently
> loaded at any given time so that I don't waste time loading things
> that are already loaded? search() tells me what's available, but
> what's loaded? The best I can find so far goes like this:
>
> > a<-.packages(all.available = FALSE)
> > a
> [1] "zoo"       "stats"     "graphics"  "grDevices" "utils"     "datasets"
> [7] "methods"   "base"
> >
>
> Maybe that's as good as it gets in code and if I want better then I
> write a function?
>
> Thanks,
> Mark
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
David Winsemius

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Mark Knecht

On Jul 3, 2009, at 1:21 PM, Mark Knecht wrote:

> Hi,
>   Two easy questions I'm sure.
>
> snipped as already answered

> 2) Related to the above, how do I tell what packages are currently
> loaded at any given time so that I don't waste time loading things
> that are already loaded? search() tells me what's available, but
> what's loaded? The best I can find so far goes like this:
>
>> a<-.packages(all.available = FALSE)
>> a
> [1] "zoo"       "stats"     "graphics"  "grDevices" "utils"      
> "datasets"
> [7] "methods"   "base"


What's wrong with using sessionInfo() ?

...or if you want (a lot) more information about the non-base packages  
try:

sessionInfo()$otherPkgs

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Duncan Murdoch

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Mark Knecht
On 7/3/2009 1:21 PM, Mark Knecht wrote:
> Hi,
>    Two easy questions I'm sure.
>
> 1) As an example if I use the code
>
> require(zoo)
>
> then once it's loaded is there a command that lists everything that
> zoo provides so that I can study the package?

ls("package:zoo") will list all the exported items in zoo, provided it
is attached. You can abbreviate that to the number in the search list,
which is usually 2 immediately after you attach the package.  So

require(zoo)
ls(2)

will probably do what you want.  Use search() to see the search list.

Duncan Murdoch

>
>    Certainly help(zoo) gives me some clues about what zoo does but I'd
> like a list. Maybe there's a way to query something but in Rgui under
> Win Vista ls() returns nothing after zoo is loaded.
>
> 2) Related to the above, how do I tell what packages are currently
> loaded at any given time so that I don't waste time loading things
> that are already loaded? search() tells me what's available, but
> what's loaded? The best I can find so far goes like this:
>
>> a<-.packages(all.available = FALSE)
>> a
> [1] "zoo"       "stats"     "graphics"  "grDevices" "utils"     "datasets"
> [7] "methods"   "base"
>>
>
> Maybe that's as good as it gets in code and if I want better then I
> write a function?
>
> Thanks,
> Mark
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Mark Knecht

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
Thanks to everyone for your answers. They were great and I think I
have what I was looking for.

Cheers,
Mark

On 7/3/09, Duncan Murdoch <[hidden email]> wrote:

> On 7/3/2009 1:21 PM, Mark Knecht wrote:
>
> > Hi,
> >   Two easy questions I'm sure.
> >
> > 1) As an example if I use the code
> >
> > require(zoo)
> >
> > then once it's loaded is there a command that lists everything that
> > zoo provides so that I can study the package?
> >
>
>  ls("package:zoo") will list all the exported items in zoo, provided it is
> attached. You can abbreviate that to the number in the search list, which is
> usually 2 immediately after you attach the package.  So
>
>  require(zoo)
>  ls(2)
>
>  will probably do what you want.  Use search() to see the search list.
>
>  Duncan Murdoch
>
>
> >
> >   Certainly help(zoo) gives me some clues about what zoo does but I'd
> > like a list. Maybe there's a way to query something but in Rgui under
> > Win Vista ls() returns nothing after zoo is loaded.
> >
> > 2) Related to the above, how do I tell what packages are currently
> > loaded at any given time so that I don't waste time loading things
> > that are already loaded? search() tells me what's available, but
> > what's loaded? The best I can find so far goes like this:
> >
> >
> > > a<-.packages(all.available = FALSE)
> > > a
> > >
> > [1] "zoo"       "stats"     "graphics"  "grDevices" "utils"     "datasets"
> > [7] "methods"   "base"
> >
> > >
> > >
> >
> > Maybe that's as good as it gets in code and if I want better then I
> > write a function?
> >
> > Thanks,
> > Mark
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Philippe Grosjean

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Duncan Murdoch
If you want a quick overview of a package (not just the name of the
objects), you can also do:

 > library(help = zoo)


Duncan Murdoch wrote:

> On 7/3/2009 1:21 PM, Mark Knecht wrote:
>> Hi,
>>    Two easy questions I'm sure.
>>
>> 1) As an example if I use the code
>>
>> require(zoo)
>>
>> then once it's loaded is there a command that lists everything that
>> zoo provides so that I can study the package?
>
> ls("package:zoo") will list all the exported items in zoo, provided it
> is attached. You can abbreviate that to the number in the search list,
> which is usually 2 immediately after you attach the package.  So
>
> require(zoo)
> ls(2)
>
> will probably do what you want.  Use search() to see the search list.
>
> Duncan Murdoch
>
>>
>>    Certainly help(zoo) gives me some clues about what zoo does but I'd
>> like a list. Maybe there's a way to query something but in Rgui under
>> Win Vista ls() returns nothing after zoo is loaded.
>>
>> 2) Related to the above, how do I tell what packages are currently
>> loaded at any given time so that I don't waste time loading things
>> that are already loaded? search() tells me what's available, but
>> what's loaded? The best I can find so far goes like this:
>>
>>> a<-.packages(all.available = FALSE)
>>> a
>> [1] "zoo"       "stats"     "graphics"  "grDevices" "utils"    
>> "datasets"
>> [7] "methods"   "base"
>>>
>>
>> Maybe that's as good as it gets in code and if I want better then I
>> write a function?
>>
>> Thanks,
>> Mark
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
hadley wickham

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Mark Knecht
> 2) Related to the above, how do I tell what packages are currently
> loaded at any given time so that I don't waste time loading things
> that are already loaded? search() tells me what's available, but
> what's loaded? The best I can find so far goes like this:

Loading something a second time takes hardly any time, so why worry about it?

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Barry Rowlingson

Re: What command lists everything in a package?

Reply Threaded More More options
Print post
Permalink
On Sun, Jul 5, 2009 at 3:40 PM, hadley wickham<[hidden email]> wrote:
>> 2) Related to the above, how do I tell what packages are currently
>> loaded at any given time so that I don't waste time loading things
>> that are already loaded? search() tells me what's available, but
>> what's loaded? The best I can find so far goes like this:
>
> Loading something a second time takes hardly any time, so why worry about it?

 library() and require() already check to see if the package is
loaded, so any test done before calling library() or require() is
going to be redundant!

 library() uses:

        pkgname <- paste("package", package, sep = ":")
        newpackage <- is.na(match(pkgname, search()))

require() uses:

        loaded <- paste("package", package, sep = ":") %in% search()

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.