Documentation for library() and how to specify missing arguments

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Documentation for library() and how to specify missing arguments

cybaea
I can, after carefully reading about the returned values, see why

library("MASS", "MASS", character.only=TRUE)

has to chose between loading the package and displaying the help (I
thought I had found a nice shortcut), but wouldn't the documentation be
better if it said that the two are incompatible and that package= takes
precedence over help=?


As an aside, is there a way to explicitly specify a missing argument in
a function call?  For an example using the same function as before,

library(, "MASS", character.only=TRUE)

displays the help but can be a little hard on the programmer's eyes.  
However,

library(NULL, "MASS", character.only=TRUE)
library(NA, "MASS", character.only=TRUE)
library({}, "MASS", character.only=TRUE)  #  signals error.

doesn't do the same at all (I thought the first one would, based on the
"whenever" in the documentation: "It is used whenever there is a need to
indicate or specify that an object is absent.").

Is there in the language a lexical x such that f(x, ...) is the same as
f(, ...)?

(Yes, I know about named arguments and I like them, I am just trying to
learn syntax here.)

Allan

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for library() and how to specify missing arguments

David Winsemius

On Jul 1, 2010, at 1:24 PM, Allan Engelhardt wrote:

> I can, after carefully reading about the returned values, see why
>
> library("MASS", "MASS", character.only=TRUE)
>
> has to chose between loading the package and displaying the help (I  
> thought I had found a nice shortcut), but wouldn't the documentation  
> be better if it said that the two are incompatible and that package=  
> takes precedence over help=?
>
>
> As an aside, is there a way to explicitly specify a missing argument  
> in a function call?  For an example using the same function as before,
>
> library(, "MASS", character.only=TRUE)

I have always used:

help(package=MASS)   # does not need to be quoted

My annoyance/whine is that various functions use "pkg", pkgs", or  
"package" as argument names. This is the only one I have successfully  
committed to memory.


>
> displays the help but can be a little hard on the programmer's  
> eyes.  However,
>
> library(NULL, "MASS", character.only=TRUE)
> library(NA, "MASS", character.only=TRUE)
> library({}, "MASS", character.only=TRUE)  #  signals error.
>
> doesn't do the same at all (I thought the first one would, based on  
> the "whenever" in the documentation: "It is used whenever there is a  
> need to indicate or specify that an object is absent.").
>
> Is there in the language a lexical x such that f(x, ...) is the same  
> as f(, ...)?
>
> (Yes, I know about named arguments and I like them, I am just trying  
> to learn syntax here.)
>
> Allan

--

David Winsemius, MD
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.
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for library() and how to specify missing arguments

Gabor Grothendieck
In reply to this post by cybaea
On Thu, Jul 1, 2010 at 1:24 PM, Allan Engelhardt <[hidden email]> wrote:
>
> Is there in the language a lexical x such that f(x, ...) is the same as f(,
> ...)?
>

Try this:

> mx <- formals(identity)$x
> missing(mx)
[1] TRUE
> sin(mx)
Error in sin(mx) : 'mx' is missing

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for library() and how to specify missing arguments

Jeffrey J. Hallman-2
Gabor Grothendieck <[hidden email]> writes:
> Try this:
>
>> mx <- formals(identity)$x
>> missing(mx)
> [1] TRUE
>> sin(mx)
> Error in sin(mx) : 'mx' is missing

Neat. There's no way to look at 'mx' because calling any function
with it as an argument gives that same error message, including the auto
print function. What exactly is 'mx' here?

--
Jeff

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: Documentation for library() and how to specify missing arguments

Gabor Grothendieck
On Fri, Jul 2, 2010 at 9:27 AM, Jeffrey J. Hallman <[hidden email]> wrote:

> Gabor Grothendieck <[hidden email]> writes:
>> Try this:
>>
>>> mx <- formals(identity)$x
>>> missing(mx)
>> [1] TRUE
>>> sin(mx)
>> Error in sin(mx) : 'mx' is missing
>
> Neat. There's no way to look at 'mx' because calling any function
> with it as an argument gives that same error message, including the auto
> print function. What exactly is 'mx' here?

You can't look at mx directly but you can look look at the expression
that generates it to see that its a component of a pairlist with class
"name" and type "symbol" :

> class(formals(identity))
[1] "pairlist"
> class(formals(identity)$x)
[1] "name"
> typeof(formals(identity)$x)
[1] "symbol"

______________________________________________
[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.