STRING_IS_SORTED claims as.character(1:100) is sorted

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

STRING_IS_SORTED claims as.character(1:100) is sorted

R devel mailing list
If I have loaded the C code:
    SEXP altrep_STRING_IS_SORTED(SEXP x)
    {
        return ScalarInteger(STRING_IS_SORTED(x));
    }
and defined the function:
    issort <- function(x) .Call("altrep_STRING_IS_SORTED",x)

I am seeing the following results in R 3.5.1/Linux:
    > issort(LETTERS)
    [1] NA
    > issort(as.character(1:100))  ## should return NA
    [1] 1
    > issort(as.character(100:1))  ## should return NA
    [1] -1
    > issort(as.character(1:100+1L))
    [1] NA

issort(as.character(1:100)) should return NA, since the string vector
"1","2",..."10",... is not sorted.  I suspect that the problem is that
the Is_sorted method for deferred_string is just calling the Is_sorted
method for the source object 1:100 (which _is_ a sorted integer
vector).  It should probably just return NA for any source object.

  ~~ Michael Sannella

        [[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: STRING_IS_SORTED claims as.character(1:100) is sorted

Gabriel Becker-2
Thank you for the report. We will look at this and make sure it gets fixed.

~G


On Thu, Nov 15, 2018, 3:13 PM Michael Sannella via R-devel <
[hidden email]> wrote:

> If I have loaded the C code:
>     SEXP altrep_STRING_IS_SORTED(SEXP x)
>     {
>         return ScalarInteger(STRING_IS_SORTED(x));
>     }
> and defined the function:
>     issort <- function(x) .Call("altrep_STRING_IS_SORTED",x)
>
> I am seeing the following results in R 3.5.1/Linux:
>     > issort(LETTERS)
>     [1] NA
>     > issort(as.character(1:100))  ## should return NA
>     [1] 1
>     > issort(as.character(100:1))  ## should return NA
>     [1] -1
>     > issort(as.character(1:100+1L))
>     [1] NA
>
> issort(as.character(1:100)) should return NA, since the string vector
> "1","2",..."10",... is not sorted.  I suspect that the problem is that
> the Is_sorted method for deferred_string is just calling the Is_sorted
> method for the source object 1:100 (which _is_ a sorted integer
> vector).  It should probably just return NA for any source object.
>
>   ~~ Michael Sannella
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [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: STRING_IS_SORTED claims as.character(1:100) is sorted

Tierney, Luke
In reply to this post by R devel mailing list
Thanks. Fixed in R_devel and R-patched. [STRING_IS_SORTED was not yet
used anywhere so this did not affect any computations.]

Best,

luke

On Thu, 15 Nov 2018, Michael Sannella via R-devel wrote:

> If I have loaded the C code:
>    SEXP altrep_STRING_IS_SORTED(SEXP x)
>    {
>        return ScalarInteger(STRING_IS_SORTED(x));
>    }
> and defined the function:
>    issort <- function(x) .Call("altrep_STRING_IS_SORTED",x)
>
> I am seeing the following results in R 3.5.1/Linux:
>    > issort(LETTERS)
>    [1] NA
>    > issort(as.character(1:100))  ## should return NA
>    [1] 1
>    > issort(as.character(100:1))  ## should return NA
>    [1] -1
>    > issort(as.character(1:100+1L))
>    [1] NA
>
> issort(as.character(1:100)) should return NA, since the string vector
> "1","2",..."10",... is not sorted.  I suspect that the problem is that
> the Is_sorted method for deferred_string is just calling the Is_sorted
> method for the source object 1:100 (which _is_ a sorted integer
> vector).  It should probably just return NA for any source object.
>
>  ~~ Michael Sannella
>
> [[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