Thanks for your input Bill. I also realised that the second argument must be initialised to 1:n, which is not mentioned in the documentation. So, if I define void mysort2i (int *x, int *i, int *n) { R_qsort_int_I(x,i,1,*n); }
Then > .C("mysort2i",4:1,integer(4),4L) [[1]] [1] 1 2 3 4 [[2]] [1] 0 0 0 0 [[3]] [1] 4 but > .C("mysort2i",4:1,1:4,4L) [[1]] [1] 1 2 3 4 [[2]] [1] 4 3 2 1 [[3]] [1] 4 ________________________________ From: Bill Dunlap <williamwdun...@gmail.com> Sent: 16 April 2021 04:50 To: Evangelos Evangelou <ee...@bath.ac.uk> Cc: r-help@r-project.org <r-help@r-project.org> Subject: Re: [R] Bug? Index output of C functions R_qsort_I and R_qsort_int_I is not modified 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@r-project.org<mailto:r-help@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<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcran.r-project.org%2Fdoc%2Fmanuals%2Fr-release%2FR-exts.html%23Utility-functions&data=04%7C01%7Cee224%40bath.ac.uk%7C10bfc437aa4c4a1de23208d9008ad510%7C377e3d224ea1422db0ad8fcc89406b9e%7C0%7C0%7C637541418550685457%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=vIt2tF%2BtNP%2B8t%2FNmUtNsP0JGRoOyo30jy1hWD%2BQI2vk%3D&reserved=0> "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@r-project.org<mailto:R-help@r-project.org> mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=04%7C01%7Cee224%40bath.ac.uk%7C10bfc437aa4c4a1de23208d9008ad510%7C377e3d224ea1422db0ad8fcc89406b9e%7C0%7C0%7C637541418550685457%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=h1Rb1vobBq49NzofsNBgZfwSqa1ZSqVhQbZT%2BBpq2ac%3D&reserved=0> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=04%7C01%7Cee224%40bath.ac.uk%7C10bfc437aa4c4a1de23208d9008ad510%7C377e3d224ea1422db0ad8fcc89406b9e%7C0%7C0%7C637541418550695414%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=yY8ALqCrEoBvQftAibVu7urh9%2FNHgmAGPgcauW%2Ff9Mo%3D&reserved=0> and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@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.