[R] Specifying arguements in user defined functions
Gabor Grothendieck
ggrothendieck at myway.com
Thu Nov 20 04:44:53 CET 2003
The list of arguments to a function and the default values,
if any, are given in online help:
?cov
You can also display the arguments and their defaults like this:
args(cov)
If you write your own function then there are no predefined
arguments. If you chose to use digits as an argument its up
to you but neither it nor any other argument has any meaning
other than what you give to it in the body of your function.
To write your own functions, read the chapter on writing
your own functions in Introduction to R, available at:
http://www.r-project.org > Manuals > Introduction to R
---
Date: Wed, 19 Nov 2003 16:45:31 -0500
From: chzieg01 <chzieg01 at athena.louisville.edu>
To: <r-help at stat.math.ethz.ch>
Subject: [R] Specifying arguements in user defined functions
Dear R subscribees,
First, I am new to R and I apologize if the question is naive. I am trying to
find out where arguments specifications
can be found. For example, the code below (at the very bottom of
this email) contains the argument 'digits' in the function 'lin' which
printout my output to the 3rd decimal place. Somebody showed me the
'digits' argument, but did not show me where to go to find other available
arguments that can be used in functions. (I have emailed this person
but receive an email saying he is out of the office)
To elaborate further, if you look at some of my
code you can see where I specify in the cov(x,y,use="pairwise.complete.obs")
or var(x,use="pairwise.complete.obs"), etc. Now for the arguments in the
'lin' function I would like to specify:
lin <- function (x,y, digits=3, use="all.obs")
or something equivalent that will delete the case if I have NA in either
the x or y variable/vector. (I get the 'use=all.obs' by just typing
'cov' at the R prompt and looking at the function body. I have tried various
combination of the 'use=all.obs' along with what looks to be necessary code
related to it such as "'na.method <- pmatch(use, c("all.obs", "complete.obs",
"pairwise.complete.obs"))'
and .Internal(cov(x, y, na.method)")
My question is where did the 'use=all.obs' argument come from. Is this
basically a function/object/argument(???) that I, a R user, have access to or
did the originator of this function create an object which is compiled within
the cor/cov/var functions, etc? If so, how do I know what function arguments
are available to me or which I have to create. If there are arguments
available to me where do I find them?
I hope this makes sense and appreciate any help you can give me in sending
me on the right path to understand this.
Thanks,
Craig Ziegler
******************************************************************************
lin <- function (x,y, digits=3) # How did the person who knew about
# the digits argument know about
# this argument other than through
# experience
{
lincc <-
(2 * cov(x,y,use="pairwise.complete.obs")) /
(var(x,use="pairwise.complete.obs") +
(var(y,use="pairwise.complete.obs"))+
((mean(x,na.rm=TRUE) - mean(y,na.rm=TRUE))^2))
print(lincc)
etc...
}
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list