From jorismeys at gmail.com  Tue Aug 26 10:44:09 2014
From: jorismeys at gmail.com (Joris Meys)
Date: Tue, 26 Aug 2014 10:44:09 +0200
Subject: [Rd] dubious behaviour of match.arg() with nested functions.
In-Reply-To: <5B378047-E835-4AA2-80FD-214E782E575C@xs4all.nl>
References: <CAO1zAVb_R22qDehCxzn7WCJhbPTYw8+aWYWzqM4KZEUJaTEnpg@mail.gmail.com>
	<5B378047-E835-4AA2-80FD-214E782E575C@xs4all.nl>
Message-ID: <CAO1zAVb_0t8DYp1VuZ42+tvoxG+zKvH17tRRn1duUwiFahKTWA@mail.gmail.com>

Dear all,

thank you for the explanations, crystal clear now. I'm also officially an
idiot. Functions in files in a package belong to that package and not to
some other package that happens to appear in the name of said function. Ah,
the merits of inheritance (inheriting a complex code base in this case...)

Cheers
Joris


On Mon, Aug 25, 2014 at 6:49 PM, Berend Hasselman <bhh at xs4all.nl> wrote:

>
> On 25-08-2014, at 16:27, Joris Meys <jorismeys at gmail.com> wrote:
>
> > Dear all,
> >
> > I initially ran into this problem while rebuilding a package dependent on
> > nleqslv. I got the following error:
> >
> > Error in match.arg(global) : 'arg' must be of length 1
> >
> > This didn't occur in previous versions of nleqslv, but did in the current
> > one (2.4). I think I pinned the problem down to the following example:
> >
> > Take two functions:
> >
> > test <- function(x=c("q","r","s"),global=c("d","e","r","z","q")){
> >  x <- match.arg(x)
> >  global <- match.arg(global)
> >  return(list(x,global))
> > }
> >
> > test2 <- function(x=c("q","r","s"),global=c("d","z","q")){
> >  test(x=x,global=global)
> > }
> >
>
> Can?t  the problem easily be avoided by using a slightly modified version
> of the test2() function?
>
> test2 <- function(x=c("q","r","s"),global=c("d","z","q")){
>  x <- match.arg(x)
> global <- match.arg(global)
>  test(x=x,global=global)
> }
>
> Then test2() would be calling test() as it was intended to be called.
> I?ve tried that and it appears to solve the problem.
>
> So before calling nleqslv within another function use match.arg on those
> arguments with the same name and different defaults.
> And (possibly) document that some arguments expect a single value.
>
> Berend
>
>


-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

	[[alternative HTML version deleted]]



[Rd] dubious behaviour of match.arg() with nested functions.
Joris Meys