exists, get and get0 accept silently inputs of length > 1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

exists, get and get0 accept silently inputs of length > 1

Antoine Fabri
Dear R-devel,

The doc of exists, get and get0 is unambiguous, x should be an object given
as a character string. However these accept longer inputs. It can lead an
uncareful user to think these functions are vectorized when they're not,
and generally lets through bugs that one might have preferred to trigger
earlier failure.

``` r
exists("d")
#> [1] FALSE
exists(c("c", "d"))
#> [1] TRUE
get(c("c", "d"))
#> function (...)  .Primitive("c")
get0(c("c", "d"))
#> function (...)  .Primitive("c")
```

I believe these should either fail, or be vectorized, probably the former.

Thanks,

Antoine

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] exists, get and get0 accept silently inputs of length > 1

luke-tierney
Worth looking into. It would probably cause some check failures, so
would probably be a good idea to run a check across BIOC/CRAN.  At the
same time it would be worth allowing name objects (type "symbol") so
thee don't have to be converted to character for the call and then
back to names internally for the environment lookup.

Best,

luke

On Fri, 13 Nov 2020, Antoine Fabri wrote:

> Dear R-devel,
>
> The doc of exists, get and get0 is unambiguous, x should be an object given
> as a character string. However these accept longer inputs. It can lead an
> uncareful user to think these functions are vectorized when they're not,
> and generally lets through bugs that one might have preferred to trigger
> earlier failure.
>
> ``` r
> exists("d")
> #> [1] FALSE
> exists(c("c", "d"))
> #> [1] TRUE
> get(c("c", "d"))
> #> function (...)  .Primitive("c")
> get0(c("c", "d"))
> #> function (...)  .Primitive("c")
> ```
>
> I believe these should either fail, or be vectorized, probably the former.
>
> Thanks,
>
> Antoine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] exists, get and get0 accept silently inputs of length > 1

Hugh Parsonage
I noticed the recent commit to R-dev (r79434).  Is this wise? I've
often used get() in constructions like

for (j in ls()) if (is.numeric(x <- get(j))) ...

(and often interactively, rather than in a package)

Am I to understand that get(j) will now be equivalent to `j` even if j
is a string referring putatively to another object?

On Sat, 14 Nov 2020 at 01:34, <[hidden email]> wrote:

>
> Worth looking into. It would probably cause some check failures, so
> would probably be a good idea to run a check across BIOC/CRAN.  At the
> same time it would be worth allowing name objects (type "symbol") so
> thee don't have to be converted to character for the call and then
> back to names internally for the environment lookup.
>
> Best,
>
> luke
>
> On Fri, 13 Nov 2020, Antoine Fabri wrote:
>
> > Dear R-devel,
> >
> > The doc of exists, get and get0 is unambiguous, x should be an object given
> > as a character string. However these accept longer inputs. It can lead an
> > uncareful user to think these functions are vectorized when they're not,
> > and generally lets through bugs that one might have preferred to trigger
> > earlier failure.
> >
> > ``` r
> > exists("d")
> > #> [1] FALSE
> > exists(c("c", "d"))
> > #> [1] TRUE
> > get(c("c", "d"))
> > #> function (...)  .Primitive("c")
> > get0(c("c", "d"))
> > #> function (...)  .Primitive("c")
> > ```
> >
> > I believe these should either fail, or be vectorized, probably the former.
> >
> > Thanks,
> >
> > Antoine
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> --
> Luke Tierney
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa                  Phone:             319-335-3386
> Department of Statistics and        Fax:               319-335-3017
>     Actuarial Science
> 241 Schaeffer Hall                  email:   [hidden email]
> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] exists, get and get0 accept silently inputs of length > 1

Gabriel Becker-2
Hi all,

I have used variable values in get() as well, and including, I think, in
package code (though pretty infrequently).

Perhaps a character.only argument similar to library?

~G

On Mon, Nov 16, 2020 at 5:31 PM Hugh Parsonage <[hidden email]>
wrote:

> I noticed the recent commit to R-dev (r79434).  Is this wise? I've
> often used get() in constructions like
>
> for (j in ls()) if (is.numeric(x <- get(j))) ...
>
> (and often interactively, rather than in a package)
>
> Am I to understand that get(j) will now be equivalent to `j` even if j
> is a string referring putatively to another object?
>
> On Sat, 14 Nov 2020 at 01:34, <[hidden email]> wrote:
> >
> > Worth looking into. It would probably cause some check failures, so
> > would probably be a good idea to run a check across BIOC/CRAN.  At the
> > same time it would be worth allowing name objects (type "symbol") so
> > thee don't have to be converted to character for the call and then
> > back to names internally for the environment lookup.
> >
> > Best,
> >
> > luke
> >
> > On Fri, 13 Nov 2020, Antoine Fabri wrote:
> >
> > > Dear R-devel,
> > >
> > > The doc of exists, get and get0 is unambiguous, x should be an object
> given
> > > as a character string. However these accept longer inputs. It can lead
> an
> > > uncareful user to think these functions are vectorized when they're
> not,
> > > and generally lets through bugs that one might have preferred to
> trigger
> > > earlier failure.
> > >
> > > ``` r
> > > exists("d")
> > > #> [1] FALSE
> > > exists(c("c", "d"))
> > > #> [1] TRUE
> > > get(c("c", "d"))
> > > #> function (...)  .Primitive("c")
> > > get0(c("c", "d"))
> > > #> function (...)  .Primitive("c")
> > > ```
> > >
> > > I believe these should either fail, or be vectorized, probably the
> former.
> > >
> > > Thanks,
> > >
> > > Antoine
> > >
> > >       [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-devel
> > >
> >
> > --
> > Luke Tierney
> > Ralph E. Wareham Professor of Mathematical Sciences
> > University of Iowa                  Phone:             319-335-3386
> > Department of Statistics and        Fax:               319-335-3017
> >     Actuarial Science
> > 241 Schaeffer Hall                  email:   [hidden email]
> > Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] exists, get and get0 accept silently inputs of length > 1

luke-tierney
Come on, folks. There is no NSE involved in calls to get(): it's
standard evaluation all the way into the C code. Prior to the change a
first argument that is anything other than a character vector would
produce an error. After the change, passing in a symbol will do the
obvious thing. Code that worked previously without error (i.e. called
get() with string values) will continue to work exactly as it did
before.

It's a little more convenient and a little more efficient for some
computations on the language not to have to call as.character on
symbols before passing them to get(). Hence the change expanding the
domain of get().

luke

On Tue, 17 Nov 2020, Gabriel Becker wrote:

> Hi all,
> I have used variable values in get() as well, and including, I think, in
> package code (though pretty infrequently).
> Perhaps a character.only argument similar to library?
>
> ~G
>
> On Mon, Nov 16, 2020 at 5:31 PM Hugh Parsonage <[hidden email]>
> wrote:
>       I noticed the recent commit to R-dev (r79434).  Is this wise?
>       I've
>       often used get() in constructions like
>
>       for (j in ls()) if (is.numeric(x <- get(j))) ...
>
>       (and often interactively, rather than in a package)
>
>       Am I to understand that get(j) will now be equivalent to `j`
>       even if j
>       is a string referring putatively to another object?
>
>       On Sat, 14 Nov 2020 at 01:34, <[hidden email]> wrote:
>       >
>       > Worth looking into. It would probably cause some check
>       failures, so
>       > would probably be a good idea to run a check across
>       BIOC/CRAN.  At the
>       > same time it would be worth allowing name objects (type
>       "symbol") so
>       > thee don't have to be converted to character for the call and
>       then
>       > back to names internally for the environment lookup.
>       >
>       > Best,
>       >
>       > luke
>       >
>       > On Fri, 13 Nov 2020, Antoine Fabri wrote:
>       >
>       > > Dear R-devel,
>       > >
>       > > The doc of exists, get and get0 is unambiguous, x should be
>       an object given
>       > > as a character string. However these accept longer inputs.
>       It can lead an
>       > > uncareful user to think these functions are vectorized when
>       they're not,
>       > > and generally lets through bugs that one might have
>       preferred to trigger
>       > > earlier failure.
>       > >
>       > > ``` r
>       > > exists("d")
>       > > #> [1] FALSE
>       > > exists(c("c", "d"))
>       > > #> [1] TRUE
>       > > get(c("c", "d"))
>       > > #> function (...)  .Primitive("c")
>       > > get0(c("c", "d"))
>       > > #> function (...)  .Primitive("c")
>       > > ```
>       > >
>       > > I believe these should either fail, or be vectorized,
>       probably the former.
>       > >
>       > > Thanks,
>       > >
>       > > Antoine
>       > >
>       > >       [[alternative HTML version deleted]]
>       > >
>       > > ______________________________________________
>       > > [hidden email] mailing list
>       > > https://stat.ethz.ch/mailman/listinfo/r-devel
>       > >
>       >
>       > --
>       > Luke Tierney
>       > Ralph E. Wareham Professor of Mathematical Sciences
>       > University of Iowa                  Phone:
>        319-335-3386
>       > Department of Statistics and        Fax:
>        319-335-3017
>       >     Actuarial Science
>       > 241 Schaeffer Hall                  email:
>        [hidden email]
>       > Iowa City, IA 52242                 WWW:
>       http://www.stat.uiowa.edu
>       >
>       > ______________________________________________
>       > [hidden email] mailing list
>       > https://stat.ethz.ch/mailman/listinfo/r-devel
>
>       ______________________________________________
>       [hidden email] mailing list
>       https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] exists, get and get0 accept silently inputs of length > 1

Gabriel Becker-2
Hi Luke et al.,

Apologies. I knew there was no NSE before but incorrectly inferred from the
previous message that some had been added. Should have looked at the commit
myself before chiming in. Sorry for the noise.

~G

On Mon, Nov 16, 2020 at 8:39 PM <[hidden email]> wrote:

> Come on, folks. There is no NSE involved in calls to get(): it's
> standard evaluation all the way into the C code. Prior to the change a
> first argument that is anything other than a character vector would
> produce an error. After the change, passing in a symbol will do the
> obvious thing. Code that worked previously without error (i.e. called
> get() with string values) will continue to work exactly as it did
> before.
>
> It's a little more convenient and a little more efficient for some
> computations on the language not to have to call as.character on
> symbols before passing them to get(). Hence the change expanding the
> domain of get().
>
> luke
>
> On Tue, 17 Nov 2020, Gabriel Becker wrote:
>
> > Hi all,
> > I have used variable values in get() as well, and including, I think, in
> > package code (though pretty infrequently).
> > Perhaps a character.only argument similar to library?
> >
> > ~G
> >
> > On Mon, Nov 16, 2020 at 5:31 PM Hugh Parsonage <[hidden email]
> >
> > wrote:
> >       I noticed the recent commit to R-dev (r79434).  Is this wise?
> >       I've
> >       often used get() in constructions like
> >
> >       for (j in ls()) if (is.numeric(x <- get(j))) ...
> >
> >       (and often interactively, rather than in a package)
> >
> >       Am I to understand that get(j) will now be equivalent to `j`
> >       even if j
> >       is a string referring putatively to another object?
> >
> >       On Sat, 14 Nov 2020 at 01:34, <[hidden email]> wrote:
> >       >
> >       > Worth looking into. It would probably cause some check
> >       failures, so
> >       > would probably be a good idea to run a check across
> >       BIOC/CRAN.  At the
> >       > same time it would be worth allowing name objects (type
> >       "symbol") so
> >       > thee don't have to be converted to character for the call and
> >       then
> >       > back to names internally for the environment lookup.
> >       >
> >       > Best,
> >       >
> >       > luke
> >       >
> >       > On Fri, 13 Nov 2020, Antoine Fabri wrote:
> >       >
> >       > > Dear R-devel,
> >       > >
> >       > > The doc of exists, get and get0 is unambiguous, x should be
> >       an object given
> >       > > as a character string. However these accept longer inputs.
> >       It can lead an
> >       > > uncareful user to think these functions are vectorized when
> >       they're not,
> >       > > and generally lets through bugs that one might have
> >       preferred to trigger
> >       > > earlier failure.
> >       > >
> >       > > ``` r
> >       > > exists("d")
> >       > > #> [1] FALSE
> >       > > exists(c("c", "d"))
> >       > > #> [1] TRUE
> >       > > get(c("c", "d"))
> >       > > #> function (...)  .Primitive("c")
> >       > > get0(c("c", "d"))
> >       > > #> function (...)  .Primitive("c")
> >       > > ```
> >       > >
> >       > > I believe these should either fail, or be vectorized,
> >       probably the former.
> >       > >
> >       > > Thanks,
> >       > >
> >       > > Antoine
> >       > >
> >       > >       [[alternative HTML version deleted]]
> >       > >
> >       > > ______________________________________________
> >       > > [hidden email] mailing list
> >       > > https://stat.ethz.ch/mailman/listinfo/r-devel
> >       > >
> >       >
> >       > --
> >       > Luke Tierney
> >       > Ralph E. Wareham Professor of Mathematical Sciences
> >       > University of Iowa                  Phone:
> >        319-335-3386
> >       > Department of Statistics and        Fax:
> >        319-335-3017
> >       >     Actuarial Science
> >       > 241 Schaeffer Hall                  email:
> >        [hidden email]
> >       > Iowa City, IA 52242                 WWW:
> >       http://www.stat.uiowa.edu
> >       >
> >       > ______________________________________________
> >       > [hidden email] mailing list
> >       > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
> >       ______________________________________________
> >       [hidden email] mailing list
> >       https://stat.ethz.ch/mailman/listinfo/r-devel
> >
> >
> >
>
> --
> Luke Tierney
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa                  Phone:             319-335-3386
> Department of Statistics and        Fax:               319-335-3017
>     Actuarial Science
> 241 Schaeffer Hall                  email:   [hidden email]
> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: [External] exists, get and get0 accept silently inputs of length > 1

luke-tierney
In reply to this post by Antoine Fabri
Thanks for the suggestion.

In R-devel (as of r79474) exists(), get(), and get0() now signal an
error if the first argument has length > 1. This will cause about 30
CRAN packages and possibly a couple of Bioconductor packages to fail
under R-devel.

getS3method() now also signals an error if the class argument has
length > 1. Calls of the form getS2method(generic, class(x)) will now
fail if class(x) has length > 1. I believe most CRAN package issues
related to this change have already been resolved, but a few may
remain.

Best,

luke

On Fri, 13 Nov 2020, Antoine Fabri wrote:

> Dear R-devel,
>
> The doc of exists, get and get0 is unambiguous, x should be an object given
> as a character string. However these accept longer inputs. It can lead an
> uncareful user to think these functions are vectorized when they're not,
> and generally lets through bugs that one might have preferred to trigger
> earlier failure.
>
> ``` r
> exists("d")
> #> [1] FALSE
> exists(c("c", "d"))
> #> [1] TRUE
> get(c("c", "d"))
> #> function (...)  .Primitive("c")
> get0(c("c", "d"))
> #> function (...)  .Primitive("c")
> ```
>
> I believe these should either fail, or be vectorized, probably the former.
>
> Thanks,
>
> Antoine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel