[R] Bug? Index output of C functions R_qsort_I and R_qsort_int_I is not modified

Bill Dunlap w||||@mwdun|@p @end|ng |rom gm@||@com
Fri Apr 16 05:50:40 CEST 2021


R_ext/Utils.h:void R_qsort_int_I(int *iv, int *II, int i, int j);

The last 2 arguments are int, not int*.  .C() passes pointers to vectors so
you cannot call this function directly from .C().

-Bill

On Thu, Apr 15, 2021 at 3:15 PM Evangelos Evangelou via R-help <
r-help using r-project.org> wrote:

> Hi all.
>
> Reading the documentation of these two functions
>
> https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Utility-functions
> "The ..._I() versions also return the sort.index() vector in I."
> I can't find anything in the documentation about sort.index(), but I'm
> guessing that I is the index that makes the input sorted, as in R's
> order(). However running the following code on
> R version 4.0.5 (2021-03-31) Platform: x86_64-pc-linux-gnu (64-bit)
> does not give me that. It just gives me the original input.
>
> Rlib = file.path(Sys.getenv("R_HOME"), "lib", paste0("libR",
> .Platform$dynlib.ext))
> dyn.load(Rlib)
> n = 4L
> ix = n:1
> i = integer(n)
> cc = .C("R_qsort_int_I", ix, i, 1L, n)
> cc[[2]]
>
> I expect 4 3 2 1, but I get 0 0 0 0. Is this a bug or have I misunderstood
> something?
>
> Best,
> Vangelis
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list