Just for the record, following Bill Dunlap's advice, I think this is
the best answer to the question as originally posed is.
myfun <- function(vec, i=stop("'i' must be supplied")){
vec[i]
}
> myfun(1:40,10)
[1] 10
> myfun(1:10)
Error in myfun(1:10) : 'i' must be supplied
>
--
Paul E. Johnson
P
On Mon, Sep 26, 2011 at 2:39 PM, Gene Leynes wrote:
> I don't understand how this function can subset by i when i is missing
>
> ## My function:
> myfun = function(vec, i){
> ret = vec[i]
> ret
> }
>
> ## My data:
> i = 10
> vec = 1:100
>
> ## Expected input and behavior:
> myfun(vec, i)
On 11-09-26 8:49 PM, David Winsemius wrote:
On Sep 26, 2011, at 8:04 PM, Duncan Murdoch wrote:
On 11-09-26 5:15 PM, David Winsemius wrote:
On Sep 26, 2011, at 4:56 PM, Duncan Murdoch wrote:
On 26/09/2011 3:39 PM, Gene Leynes wrote:
I don't understand how this function can subset by i when
On Sep 26, 2011, at 8:04 PM, Duncan Murdoch wrote:
On 11-09-26 5:15 PM, David Winsemius wrote:
On Sep 26, 2011, at 4:56 PM, Duncan Murdoch wrote:
On 26/09/2011 3:39 PM, Gene Leynes wrote:
I don't understand how this function can subset by i when i is
missing
## My function:
myfun = fu
Alan and Duncan,
or test them explicitly with missing(). If you want to do this
> automatically, then you shouldn't be using substrings and deparse, you
> should work at the language level. But I don't see the reason you want to
> do this...
>
Absolutely. That wasn't the way I wanted to do it,
Actually, this version is more general, doesn't need to know the name of the
function:
f = function(x,y){
curfun = deparse(match.call()[1])
curfun = substr(curfun,1,nchar(curfun)-2)
if(length(formals(curfun))!=nargs())
stop('Something is missing...')
}
f()
Putting this code at
On 11-09-26 5:15 PM, David Winsemius wrote:
On Sep 26, 2011, at 4:56 PM, Duncan Murdoch wrote:
On 26/09/2011 3:39 PM, Gene Leynes wrote:
I don't understand how this function can subset by i when i is
missing
## My function:
myfun = function(vec, i){
ret = vec[i]
ret
}
## My da
On Mon, Sep 26, 2011 at 3:39 PM, Gene Leynes wrote:
> I don't understand how this function can subset by i when i is missing
>
> ## My function:
> myfun = function(vec, i){
> ret = vec[i]
> ret
> }
>
> ## My data:
> i = 10
> vec = 1:100
>
> ## Expected input and behavior:
> myfun(vec, i)
On Sep 26, 2011, at 4:56 PM, Duncan Murdoch wrote:
On 26/09/2011 3:39 PM, Gene Leynes wrote:
I don't understand how this function can subset by i when i is
missing
## My function:
myfun = function(vec, i){
ret = vec[i]
ret
}
## My data:
i = 10
vec = 1:100
## Expected input and
On 26/09/2011 3:39 PM, Gene Leynes wrote:
I don't understand how this function can subset by i when i is missing
## My function:
myfun = function(vec, i){
ret = vec[i]
ret
}
## My data:
i = 10
vec = 1:100
## Expected input and behavior:
myfun(vec, i)
## Missing an argument, but
I don't understand how this function can subset by i when i is missing
## My function:
myfun = function(vec, i){
ret = vec[i]
ret
}
## My data:
i = 10
vec = 1:100
## Expected input and behavior:
myfun(vec, i)
## Missing an argument, but error is not caught!
## How is subsetting even
11 matches
Mail list logo