Re: [Rd] How to get utf8 string using R externals

2021-06-02 Thread Morgan Morgan
On Wed, 2 Jun 2021, 22:31 Duncan Murdoch,  wrote:

> On 02/06/2021 4:33 p.m., xiaoyan yu wrote:
> > I have a R Script Predict.R:
> >  set.seed(42)
> >  C <- seq(1:1000)
> >  A <- rep(seq(1:200),5)
> >  E <- (seq(1:1000) * (0.8 + (0.4*runif(50, 0, 1
> >  L <- ifelse(runif(1000)>.5,1,0)
> >  df <- data.frame(cbind(C, A, E, L))
> > load("C:/Temp/tree.RData")#  load the model for scoring
> >
> >P <- as.character(predict(tree_model_1,df,type='class'))
> >
> > Then in a C++ program
> > I call eval to evaluate the script and then findVar the P variable.
> > After get each class label from P using string_elt and then
> > Rf_translateChar, the characters are unicodes () instead
> of
> > utf8 encoding of the korean characters 부실.
> > Can I know how to get UTF8 by using R externals?
> >
> > I also found the same script giving utf8 characters in RGui but unicode
> in
> > Rterm.
> > I tried to attach a screenshot but got message "The message's content
> type
> > was not explicitly allowed"
> > In RGui, I saw the output 부실, while in Rterm, .
>
> Sounds like you're using Windows.  Stop doing that.
>
> Duncan Murdoch
>

Could as well say: "Sounds like you are using R. Stop doing that." Start
using Julia. ;-)



> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [R-pkg-devel] Best practice for accessing fat JAR Java application in R package

2021-05-01 Thread Morgan Morgan
Hi,

I am not knowledgeable on the topic but if it helps you I know the h2o
package as one pretty fat file(s):
https://cran.r-project.org/web/checks/check_results_h2o.html

It requires java as well.

Also found the following link on google:
https://thecoatlessprofessor.com/programming/r/size-and-limitations-of-packages-on-cran/

Hopefully someone else will be able to provide you with better guidance.

Best regards
Morgan

On Sat, 1 May 2021, 13:40 Leifeld, Philip, 
wrote:

> Dear all,
>
> I wrote an open-source Java software, which I release as a stand-alone
> JAR file. I also wrote an R package, which adds functionality and some
> wrapper functions for the JAR for use without GUI from R. It uses rJava
> for this purpose. So far, I released both the JAR and the R package on
> GitHub and included a function in the R package that would allow the
> user to download the latest JAR and store it in the package installation
> directory under java/.
>
> But this causes unreliability for several reasons. GitHub allows only so
> many downloads per time unit, which occasionally messes up testing and
> end user experience; users sometimes end up with incompatible versions;
> it adds an inconvenient step for the user etc. I was thinking it may be
> more reliable to bundle the two pieces together by including the JAR
> file in the /inst/java directory of the package sources. This would also
> allow me to initialize Java with the JAR file upon loading the package
> without asking the user to download or initialize anything.
>
> However, the JAR file depends on other open-source software in the form
> of JAR files packaged into my JAR file (so my JAR file is a "fat" JAR
> file). For example, I access SQLite databases as part of my Java
> program, and for this I need the SQLite JDBC JAR, which has about 7MB.
> This leads to a note during R CMD check, which, I guess, will prevent
> CRAN submission:
>
> N  checking installed package size ...
>   installed size is  9.1Mb
>   sub-directories of 1Mb or more:
> java   8.1Mb
>
> As an alternative solution, I wrote a function that would download the
> correct version of the JAR file and store it in inst/java. This function
> would be executed in R/zzz.R during installation. I was hoping the
> freshly downloaded JAR file would then be copied from inst/java to java/
> in the installation directory of the package in the library path, but
> this does not seem to be the case. Even if it were copied to the desired
> location, the installed package size would still be too large and would
> yield a note.
>
> I would be grateful if somebody could suggest a best practice to deal
> with this problem. Should I aim to include the JAR or store it online?
> If include, how do I deal with the size limitation of the R package for
> CRAN? If store online, how do I deal with the unreliability of GitHub
> and other issues?
>
> Many thanks in advance,
>
> Philip
>
> --
> Philip Leifeld
> Professor, Department of Government
> University of Essex
> http://www.philipleifeld.com
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [Rd] R Console Bug?

2021-04-17 Thread Morgan Morgan
Hi Simon,
Thank you for the feedback.
It is really strange that you have a different output.
I have attached a picture of my R console.
I am just trying to port some pure C code that prints progress bars to R
but it does not seem to be printing properly.
It seems I am doing something wrong with REprintf and R_FlushConsole.
Best regards,
Morgan

On Sat, Apr 17, 2021 at 12:36 AM Simon Urbanek 
wrote:

> Sorry, unable to reproduce on macOS, in R console:
>
> > dyn.load("test.so")
> > .Call("printtest",1e4L)
>
>Processing data chunk 1 of 3
>  [==] 100%
>
>Processing data chunk 2 of 3
>  [==] 100%
>
>Processing data chunk 3 of 3
>  [==] 100%
> NULL
>
> But honestly I'm not sure sure I understand the report. R_FlushConsole is
> a no-op for terminal console and your code just prints on stderr anyway
> (which is not buffered). All this does is just a lot of \r output (which is
> highly inefficient anywhere but in Terminal by definition). Can you clarify
> what the code tries to trigger?
>
> Cheers,
> Simon
>
>
> > On Apr 16, 2021, at 23:11, Morgan Morgan 
> wrote:
> >
> > Hi,
> >
> > I am getting a really weird behaviour with the R console.
> > Here is the code to reproduce it.
> >
> > 1/ C code: ---
> >
> > SEXP printtest(SEXP x) {
> >  const int PBWIDTH = 30, loop = INTEGER(x)[0];
> >  int val, lpad;
> >  double perc;
> >  char PBSTR[PBWIDTH], PBOUT[PBWIDTH];
> >  memset(PBSTR,'=', sizeof(PBSTR));
> >  memset(PBOUT,'-', sizeof(PBOUT));
> >  for (int k = 0; k < 3; ++k) {
> >REprintf("\n   Processing data chunk %d of 3\n",k+1);
> >for (int i = 0; i < loop; ++i) {
> >  perc = (double) i/(loop-1);
> >  val  = (int) (perc * 100);
> >  lpad = (int) (perc * PBWIDTH);
> >  REprintf("\r [%.*s%.*s] %3d%%", lpad, PBSTR, PBWIDTH - lpad, PBOUT,
> > val);
> >  R_FlushConsole();
> >}
> >REprintf("\n");
> >  }
> >  return R_NilValue;
> > }
> >
> > 2/ Build so/dll: ---
> >
> > R CMD SHLIB
> >
> > 3/ Run code :  ---
> >
> > dyn.load("test.so")
> > .Call("printtest",1e4L)
> > dyn.unload("test.so")
> >
> > 4/ Issue:  ---
> > If you run the above code in RStudio, it works well both on Mac and
> Windows.
> > If you run it in Windows cmd, it is slow.
> > If you run it in Windows RGui, it is slow but also all texts are flushed.
> > If you run it in Mac terminal, it runs perfectly.
> > If you run it in Mac R Console, it prints something like :
> >> .Call("printtest",1e4L)
> > [==] 100%NULL]
>  0%
> >
> > I am using R 4.0.4 (Mac) / 4.0.5 (Windows)
> >
> > Is that a bug or am I doing something wrong?
> >
> > Thank you
> > Best regards,
> > Morgan
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] R Console Bug?

2021-04-16 Thread Morgan Morgan
Hi,

I am getting a really weird behaviour with the R console.
Here is the code to reproduce it.

1/ C code: ---

SEXP printtest(SEXP x) {
  const int PBWIDTH = 30, loop = INTEGER(x)[0];
  int val, lpad;
  double perc;
  char PBSTR[PBWIDTH], PBOUT[PBWIDTH];
  memset(PBSTR,'=', sizeof(PBSTR));
  memset(PBOUT,'-', sizeof(PBOUT));
  for (int k = 0; k < 3; ++k) {
REprintf("\n   Processing data chunk %d of 3\n",k+1);
for (int i = 0; i < loop; ++i) {
  perc = (double) i/(loop-1);
  val  = (int) (perc * 100);
  lpad = (int) (perc * PBWIDTH);
  REprintf("\r [%.*s%.*s] %3d%%", lpad, PBSTR, PBWIDTH - lpad, PBOUT,
val);
  R_FlushConsole();
}
REprintf("\n");
  }
  return R_NilValue;
}

2/ Build so/dll: ---

R CMD SHLIB

3/ Run code :  ---

dyn.load("test.so")
.Call("printtest",1e4L)
dyn.unload("test.so")

4/ Issue:  ---
If you run the above code in RStudio, it works well both on Mac and Windows.
If you run it in Windows cmd, it is slow.
If you run it in Windows RGui, it is slow but also all texts are flushed.
If you run it in Mac terminal, it runs perfectly.
If you run it in Mac R Console, it prints something like :
> .Call("printtest",1e4L)
 [==] 100%NULL]   0%

I am using R 4.0.4 (Mac) / 4.0.5 (Windows)

Is that a bug or am I doing something wrong?

Thank you
Best regards,
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Faster sorting algorithm...

2021-03-22 Thread Morgan Morgan
My apologies to Professor Neal.
Thank you for correcting me.
Best regards
Morgan


On Mon, 22 Mar 2021, 05:05 ,  wrote:

> I think it is "Professor Neal" :)
>
> I also appreciate the pqR comparisons.
>
> On Wed, Mar 17, 2021 at 09:23:15AM +, Morgan Morgan wrote:
> >Thank you Neal. This is interesting. I will have a look at pqR.
> >Indeed radix only does C collation, I believe that is why it is not the
> >default choice for character ordering and sorting.
> >Not sure but I believe it can help address the following bugzilla item:
> >https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17400
> >
> >On the same topic of collation, there is an experimental sorting function
> >"psort" in package kit that might help address this issue.
> >
> >> library(kit)
> >Attaching kit 0.0.7 (OPENMP enabled using 1 thread)
> >> x <- c("b","A","B","a","\xe4")
> >> Encoding(x) <- "latin1"
> >> identical(psort(x, c.locale=FALSE), sort(x))
> >[1] TRUE
> >> identical(psort(x, c.locale=TRUE), sort(x, method="radix"))
> >[1] TRUE
> >
> >Coming back to the topic of fsort, I have just finished the implementation
> >for double, integer, factor and logical.
> >The implementation takes into account NA, Inf.. values. Values can be
> >sorted in a decreasing order or increasing order.
> >Comparing benchmark with the current implementation in data.table, it is
> >currently over 30% faster.
> >There might bugs but I am sure performance can be further improved as I
> did
> >not really try hard.
> >If there is interest in both the implementation and cross community
> >sharing, please let know
> >
> >Best regards,
> >Morgan
> >
> >On Wed, 17 Mar 2021, 00:37 Radford Neal,  wrote:
> >
> >> Those interested in faster sorting may want to look at the merge sort
> >> implemented in pqR (see pqR-project.org).  It's often used as the
> >> default, because it is stable, and does different collations, while
> >> being faster than shell sort (except for small vectors).
> >>
> >> Here are examples, with timings, for pqR-2020-07-23 and R-4.0.2,
> >> compiled identically:
> >>
> >> -
> >> pqR-2020-07-23 in C locale:
> >>
> >> > set.seed(1)
> >> > N <- 100
> >> > x <- as.character (sample(N,N,replace=TRUE))
> >> > print(system.time (os <- order(x,method="shell")))
> >>user  system elapsed
> >>   1.332   0.000   1.334
> >> > print(system.time (or <- order(x,method="radix")))
> >>user  system elapsed
> >>   0.092   0.004   0.096
> >> > print(system.time (om <- order(x,method="merge")))
> >>user  system elapsed
> >>   0.363   0.000   0.363
> >> > print(identical(os,or))
> >> [1] TRUE
> >> > print(identical(os,om))
> >> [1] TRUE
> >> >
> >> > x <- c("a","~")
> >> > print(order(x,method="shell"))
> >> [1] 1 2
> >> > print(order(x,method="radix"))
> >> [1] 1 2
> >> > print(order(x,method="merge"))
> >> [1] 1 2
> >>
> >> -
> >> R-4.0.2 in C locale:
> >>
> >> > set.seed(1)
> >> > N <- 100
> >> > x <- as.character (sample(N,N,replace=TRUE))
> >> > print(system.time (os <- order(x,method="shell")))
> >>user  system elapsed
> >>   2.381   0.004   2.387
> >> > print(system.time (or <- order(x,method="radix")))
> >>user  system elapsed
> >>   0.138   0.000   0.137
> >> > #print(system.time (om <- order(x,method="merge")))
> >> > print(identical(os,or))
> >> [1] TRUE
> >> > #print(identical(os,om))
> >> >
> >> > x <- c("a","~")
> >> > print(order(x,method="shell"))
> >> [1] 1 2
> >> > print(order(x,method="radix"))
> >> [1] 1 2
> >> > #print(order(x,method="merge"))
> >>
> >> 
> >> pqR-2020-07-23 in fr_CA.utf8 locale:
> >>
> >> > set.seed(1)
> >> > N <- 100
> >> > x <- as.character (sample(N,N,replace=TRUE))
> >> > print(system.time (

Re: [Rd] Faster sorting algorithm...

2021-03-17 Thread Morgan Morgan
Thank you Neal. This is interesting. I will have a look at pqR.
Indeed radix only does C collation, I believe that is why it is not the
default choice for character ordering and sorting.
Not sure but I believe it can help address the following bugzilla item:
https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17400

On the same topic of collation, there is an experimental sorting function
"psort" in package kit that might help address this issue.

> library(kit)
Attaching kit 0.0.7 (OPENMP enabled using 1 thread)
> x <- c("b","A","B","a","\xe4")
> Encoding(x) <- "latin1"
> identical(psort(x, c.locale=FALSE), sort(x))
[1] TRUE
> identical(psort(x, c.locale=TRUE), sort(x, method="radix"))
[1] TRUE

Coming back to the topic of fsort, I have just finished the implementation
for double, integer, factor and logical.
The implementation takes into account NA, Inf.. values. Values can be
sorted in a decreasing order or increasing order.
Comparing benchmark with the current implementation in data.table, it is
currently over 30% faster.
There might bugs but I am sure performance can be further improved as I did
not really try hard.
If there is interest in both the implementation and cross community
sharing, please let know

Best regards,
Morgan

On Wed, 17 Mar 2021, 00:37 Radford Neal,  wrote:

> Those interested in faster sorting may want to look at the merge sort
> implemented in pqR (see pqR-project.org).  It's often used as the
> default, because it is stable, and does different collations, while
> being faster than shell sort (except for small vectors).
>
> Here are examples, with timings, for pqR-2020-07-23 and R-4.0.2,
> compiled identically:
>
> -
> pqR-2020-07-23 in C locale:
>
> > set.seed(1)
> > N <- 100
> > x <- as.character (sample(N,N,replace=TRUE))
> > print(system.time (os <- order(x,method="shell")))
>user  system elapsed
>   1.332   0.000   1.334
> > print(system.time (or <- order(x,method="radix")))
>user  system elapsed
>   0.092   0.004   0.096
> > print(system.time (om <- order(x,method="merge")))
>user  system elapsed
>   0.363   0.000   0.363
> > print(identical(os,or))
> [1] TRUE
> > print(identical(os,om))
> [1] TRUE
> >
> > x <- c("a","~")
> > print(order(x,method="shell"))
> [1] 1 2
> > print(order(x,method="radix"))
> [1] 1 2
> > print(order(x,method="merge"))
> [1] 1 2
>
> -
> R-4.0.2 in C locale:
>
> > set.seed(1)
> > N <- 100
> > x <- as.character (sample(N,N,replace=TRUE))
> > print(system.time (os <- order(x,method="shell")))
>user  system elapsed
>   2.381   0.004   2.387
> > print(system.time (or <- order(x,method="radix")))
>user  system elapsed
>   0.138   0.000   0.137
> > #print(system.time (om <- order(x,method="merge")))
> > print(identical(os,or))
> [1] TRUE
> > #print(identical(os,om))
> >
> > x <- c("a","~")
> > print(order(x,method="shell"))
> [1] 1 2
> > print(order(x,method="radix"))
> [1] 1 2
> > #print(order(x,method="merge"))
>
> 
> pqR-2020-07-23 in fr_CA.utf8 locale:
>
> > set.seed(1)
> > N <- 100
> > x <- as.character (sample(N,N,replace=TRUE))
> > print(system.time (os <- order(x,method="shell")))
> utilisateur système  écoulé
>   2.960   0.000   2.962
> > print(system.time (or <- order(x,method="radix")))
> utilisateur système  écoulé
>   0.083   0.008   0.092
> > print(system.time (om <- order(x,method="merge")))
> utilisateur système  écoulé
>   1.143   0.000   1.142
> > print(identical(os,or))
> [1] TRUE
> > print(identical(os,om))
> [1] TRUE
> >
> > x <- c("a","~")
> > print(order(x,method="shell"))
> [1] 2 1
> > print(order(x,method="radix"))
> [1] 1 2
> > print(order(x,method="merge"))
> [1] 2 1
>
> 
> R-4.0.2 in fr_CA.utf8 locale:
>
> > set.seed(1)
> > N <- 100
> > x <- as.character (sample(N,N,replace=TRUE))
> > print(system.time (os <- order(x,method="shell")))
> utilisateur système  écoulé
>   4.222   0.016   4.239
> > print(system.time (or <- order(x,method="radix")))
> utilisateur système  écoulé
>   0.136   0.000   0.137
> > #print(system.time (om <- order(x,method="merge")))
> > print(identical(os,or))
> [1] TRUE
> > #print(identical(os,om))
> >
> > x <- c("a","~")
> > print(order(x,method="shell"))
> [1] 2 1
> > print(order(x,method="radix"))
> [1] 1 2
> > #print(order(x,method="merge"))
>
>
> pqR is faster in all the tests, but more relevant to this discussion
> is that the "merge" method is substantially faster than "shell" for
> these character vectors with a million elements, while retaining the
> stability and collation properties of "shell" (whereas "radix" only
> does C collation).
>
> It would probably not be too hard to take the merge sort code from pqR
> and use it in R core's implementation.
>
> The merge sort in pqR doesn't exploit parallelism at the moment, but
> merge 

Re: [Rd] Faster sorting algorithm...

2021-03-15 Thread Morgan Morgan
Default method for sort is not radix(especially for character vector). You
might want to read the documentation of sort.
For your second question, I invite you to look at the code of fsort. It is
implemented only for positive finite double, and default to
data.table:::forder ... when the types are different than positive double...
Please read the pdf link I sent, everything is explained in it.
Thank you
Morgan

On Mon, 15 Mar 2021, 16:52 Avraham Adler,  wrote:

> Isn’t the default method now “radix” which is the data.table sort, and
> isn’t that already parallel using openmp where available?
>
> Avi
>
> On Mon, Mar 15, 2021 at 12:26 PM Morgan Morgan 
> wrote:
>
>> Hi,
>> I am not sure if this is the right mailing list, so apologies in advance
>> if
>> it is not.
>>
>> I found the following link/presentation:
>> https://www.r-project.org/dsc/2016/slides/ParallelSort.pdf
>>
>> The implementation of fsort is interesting but incomplete (not sure why?)
>> and can be improved or made faster (at least 25%  I believe). I might be
>> wrong but there are maybe a couple of bugs as well.
>>
>> My questions are:
>>
>> 1/ Is the R Core team interested in a faster sorting algo? (Multithread or
>> even single threaded)
>>
>> 2/ I see an issue with the license, which is MPL-2.0, and hence not
>> compatible with base R, Python and Julia. Is there an interest to change
>> the license of fsort so all 3 languages (and all the people using these
>> languages) can benefit from it? (Like suggested on the first page)
>>
>> Please let me know if there is an interest to address the above points, I
>> would be happy to look into it (free of charge of course!).
>>
>> Thank you
>> Best regards
>> Morgan
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
> --
> Sent from Gmail Mobile
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Faster sorting algorithm...

2021-03-15 Thread Morgan Morgan
Hi,
I am not sure if this is the right mailing list, so apologies in advance if
it is not.

I found the following link/presentation:
https://www.r-project.org/dsc/2016/slides/ParallelSort.pdf

The implementation of fsort is interesting but incomplete (not sure why?)
and can be improved or made faster (at least 25%  I believe). I might be
wrong but there are maybe a couple of bugs as well.

My questions are:

1/ Is the R Core team interested in a faster sorting algo? (Multithread or
even single threaded)

2/ I see an issue with the license, which is MPL-2.0, and hence not
compatible with base R, Python and Julia. Is there an interest to change
the license of fsort so all 3 languages (and all the people using these
languages) can benefit from it? (Like suggested on the first page)

Please let me know if there is an interest to address the above points, I
would be happy to look into it (free of charge of course!).

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[R-pkg-devel] ISNAN warning [-Wfloat-conversion]

2020-07-10 Thread Morgan Morgan
Hi,

Please see below warning from GCC (rtools 4.0).
I know that the flag "-Wconversion" is not used by default when building
packages in R but I was wondering if the below warning can be avoided by
changing the ISNAN function in the R C API?
The functions R_IsNaN and R_IsNA do not generate these warnings but they
also have  a different behaviour than ISNAN.

test_ISNAN = inline::cfunction(
  verbose = TRUE,
  language = "C",
  cppargs = "-Wconversion",
  sig = c(x = "SEXP"),
  body = "
  if (ISNAN(asReal(x))) {
Rprintf(\"Hello\");
  }
  return R_NilValue;
")

Setting PKG_CPPFLAGS to -Wconversion
Compilation argument:
 C:/PROGRA~1/R/R-40~1.0/bin/x64/R CMD SHLIB filed40200e5009.c 2>
filed40200e5009.c.err.txt
"C:/rtools40/mingw64/bin/"gcc  -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG
-Wconversion -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2
-mstackrealign -c filed40200e5009.c -o filed40200e5009.o
In file included from C:/PROGRA~1/R/R-40~1.0/include/R.h:58,
 from filed40200e5009.c:1:
filed40200e5009.c: In function 'filed40200e5009':
C:/PROGRA~1/R/R-40~1.0/include/Rinternals.h:1531:18: warning: conversion
from 'double' to 'float' may change value [-Wfloat-conversion]
 #define asReal   Rf_asReal
filed40200e5009.c:8:7: note: in expansion of macro 'ISNAN'
   if (ISNAN(asReal(x))) {
   ^
filed40200e5009.c:8:13: note: in expansion of macro 'asReal'
   if (ISNAN(asReal(x))) {
 ^~
C:/rtools40/mingw64/bin/gcc -shared -s -static-libgcc -o
filed40200e5009.dll tmp.def filed40200e5009.o
-LC:/PROGRA~1/R/R-40~1.0/bin/x64 -lR
Program source:
  1: #include 
  2: #include 
  3: #include 
  4:
  5:
  6: SEXP filed40200e5009 ( SEXP x ) {
  7:
  8:   if (ISNAN(asReal(x))) {
  9: Rprintf("Hello");
 10:   }
 11:   return R_NilValue;
 12:
 13:   warning("your C program does not return anything!");
 14:   return R_NilValue;
 15: }

Thank you
Best regards,
Morgan

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [Rd] Build a R call at C level

2020-06-30 Thread Morgan Morgan
Sorry Dirk, I don't remember discussing this topic or alternatives with you
at all.
Have a nice day.

On Tue, 30 Jun 2020, 14:42 Morgan Morgan,  wrote:

> Thanks Jan and Tomas for the feedback.
> Answer from Jan is what I am looking for.
> Maybe I am not looking in the right place buy it is not easy to understand
> how these LCONS, CONS, SETCDR...etc works.
>
> Thank you
> Best regards
> Morgan
>
>
>
> On Tue, 30 Jun 2020, 12:36 Tomas Kalibera, 
> wrote:
>
>> On 6/30/20 1:06 PM, Jan Gorecki wrote:
>> > It is quite known that R documentation on R C api could be improved...
>>
>> Please see "5.11 Evaluating R expressions from C" from "Writing R
>> Extensions"
>>
>> Best
>> Tomas
>>
>> > Still R-package-devel mailing list should be preferred for this kind
>> > of questions.
>> > Not sure if that is the best way, but works.
>> >
>> > call_to_sum <- inline::cfunction(
>> >language = "C",
>> >sig = c(x = "SEXP"), body = "
>> >
>> > SEXP e = PROTECT(lang2(install(\"sum\"), x));
>> > SEXP r_true = PROTECT(CONS(ScalarLogical(1), R_NilValue));
>> > SETCDR(CDR(e), r_true);
>> > SET_TAG(CDDR(e), install(\"na.rm\"));
>> > Rf_PrintValue(e);
>> > SEXP ans = PROTECT(eval(e, R_GlobalEnv));
>> > UNPROTECT(3);
>> > return ans;
>> >
>> > ")
>> >
>> > call_to_sum(c(1L,NA,3L))
>> >
>> > On Tue, Jun 30, 2020 at 10:08 AM Morgan Morgan
>> >  wrote:
>> >> Hi All,
>> >>
>> >> I was reading the R extension manual section 5.11 ( Evaluating R
>> expression
>> >> from C) and I tried to build a simple call to the sum function. Please
>> see
>> >> below.
>> >>
>> >> call_to_sum <- inline::cfunction(
>> >>language = "C",
>> >>sig = c(x = "SEXP"), body = "
>> >>
>> >> SEXP e = PROTECT(lang2(install(\"sum\"), x));
>> >> SEXP ans = PROTECT(eval(e, R_GlobalEnv));
>> >> UNPROTECT(2);
>> >> return ans;
>> >>
>> >> ")
>> >>
>> >> call_to_sum(1:3)
>> >>
>> >> The above works. My question is how do I add the argument "na.rm=TRUE"
>> at C
>> >> level to the above call? I have tried various things based on what is
>> in
>> >> section 5.11 but I did not manage to get it to work.
>> >>
>> >> Thank you
>> >> Best regards
>> >>
>> >>  [[alternative HTML version deleted]]
>> >>
>> >> __
>> >> R-devel@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-devel
>> > __
>> > R-devel@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Build a R call at C level

2020-06-30 Thread Morgan Morgan
Thanks Jan and Tomas for the feedback.
Answer from Jan is what I am looking for.
Maybe I am not looking in the right place buy it is not easy to understand
how these LCONS, CONS, SETCDR...etc works.

Thank you
Best regards
Morgan



On Tue, 30 Jun 2020, 12:36 Tomas Kalibera,  wrote:

> On 6/30/20 1:06 PM, Jan Gorecki wrote:
> > It is quite known that R documentation on R C api could be improved...
>
> Please see "5.11 Evaluating R expressions from C" from "Writing R
> Extensions"
>
> Best
> Tomas
>
> > Still R-package-devel mailing list should be preferred for this kind
> > of questions.
> > Not sure if that is the best way, but works.
> >
> > call_to_sum <- inline::cfunction(
> >language = "C",
> >sig = c(x = "SEXP"), body = "
> >
> > SEXP e = PROTECT(lang2(install(\"sum\"), x));
> > SEXP r_true = PROTECT(CONS(ScalarLogical(1), R_NilValue));
> > SETCDR(CDR(e), r_true);
> > SET_TAG(CDDR(e), install(\"na.rm\"));
> > Rf_PrintValue(e);
> > SEXP ans = PROTECT(eval(e, R_GlobalEnv));
> > UNPROTECT(3);
> > return ans;
> >
> > ")
> >
> > call_to_sum(c(1L,NA,3L))
> >
> > On Tue, Jun 30, 2020 at 10:08 AM Morgan Morgan
> >  wrote:
> >> Hi All,
> >>
> >> I was reading the R extension manual section 5.11 ( Evaluating R
> expression
> >> from C) and I tried to build a simple call to the sum function. Please
> see
> >> below.
> >>
> >> call_to_sum <- inline::cfunction(
> >>language = "C",
> >>sig = c(x = "SEXP"), body = "
> >>
> >> SEXP e = PROTECT(lang2(install(\"sum\"), x));
> >> SEXP ans = PROTECT(eval(e, R_GlobalEnv));
> >> UNPROTECT(2);
> >> return ans;
> >>
> >> ")
> >>
> >> call_to_sum(1:3)
> >>
> >> The above works. My question is how do I add the argument "na.rm=TRUE"
> at C
> >> level to the above call? I have tried various things based on what is in
> >> section 5.11 but I did not manage to get it to work.
> >>
> >> Thank you
> >> Best regards
> >>
> >>  [[alternative HTML version deleted]]
> >>
> >> __
> >> R-devel@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Build a R call at C level

2020-06-30 Thread Morgan Morgan
Hi All,

I was reading the R extension manual section 5.11 ( Evaluating R expression
from C) and I tried to build a simple call to the sum function. Please see
below.

call_to_sum <- inline::cfunction(
  language = "C",
  sig = c(x = "SEXP"), body = "

SEXP e = PROTECT(lang2(install(\"sum\"), x));
SEXP ans = PROTECT(eval(e, R_GlobalEnv));
UNPROTECT(2);
return ans;

")

call_to_sum(1:3)

The above works. My question is how do I add the argument "na.rm=TRUE" at C
level to the above call? I have tried various things based on what is in
section 5.11 but I did not manage to get it to work.

Thank you
Best regards

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] subset data.frame at C level

2020-06-24 Thread Morgan Morgan
Thank you Jim for the feedback.

I actually implemented it the way I describe it in my first email and it
seems fast enough for me.

Just to give a bit of context I will need it at some point in package kit.
I also implemented subset by row which I actually need more as I am working
on a faster version of the unique and duplicated function. The function
unique is particularly slow for data.frame. So far I got a 100x speedup.

Best regards
Morgan


On Tue, 23 Jun 2020, 21:11 Jim Hester,  wrote:

> It looks to me like internally .subset2 uses `get1index()`, but this
> function is declared in Defn.h, which AFAIK is not part of the exported R
> API.
>
>  Looking at the code for `get1index()` it looks like it just loops over
> the (translated) names, so I guess I just do that [0].
>
> [0]:
> https://github.com/r-devel/r-svn/blob/1ff1d4197495a6ee1e1d88348a03ff841fd27608/src/main/subscript.c#L226-L235
>
> On Wed, Jun 17, 2020 at 6:11 AM Morgan Morgan 
> wrote:
>
>> Hi,
>>
>> Hope you are well.
>>
>> I was wondering if there is a function at C level that is equivalent to
>> mtcars$carb or .subset2(mtcars, "carb").
>>
>> If I have the index of the column then the answer would be VECTOR_ELT(df,
>> asInteger(idx)) but I was wondering if there is a way to do it directly
>> from the name of the column without having to loop over columns names to
>> find the index?
>>
>> Thank you
>> Best regards
>> Morgan
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] subset data.frame at C level

2020-06-17 Thread Morgan Morgan
Hi,

Hope you are well.

I was wondering if there is a function at C level that is equivalent to
mtcars$carb or .subset2(mtcars, "carb").

If I have the index of the column then the answer would be VECTOR_ELT(df,
asInteger(idx)) but I was wondering if there is a way to do it directly
from the name of the column without having to loop over columns names to
find the index?

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Precision of function mean,bug?

2020-05-21 Thread Morgan Morgan
Sorry, posting back to the list.
Thank you all.
Morgan

On Thu, 21 May 2020, 16:33 Henrik Bengtsson, 
wrote:

> Hi.
>
> Good point and a good example. Feel free to post to the list. The purpose
> of my reply wasn't to take away Peter's point but to emphasize that
> base::mean() does a two-pass scan over the elements too lower the impact of
> addition of values with widely different values (classical problem in
> numerical analysis). But I can see how it may look like that.
>
> Cheers,
>
> Henrik
>
>
> On Thu, May 21, 2020, 03:21 Morgan Morgan 
> wrote:
>
>> Thank you Henrik for the feedback.
>> Note that for idx=4 and refine = TRUE,  your equality b==c is FALSE. I
>> think that as Peter said == can't be trusted with FP.
>> His example is good. Here is an even more shocking one.
>> a=0.786546798
>> b=a+ 1e6 -1e6
>> a==b
>> # [1] FALSE
>>
>> Best regards
>> Morgan Jacob
>>
>> On Wed, 20 May 2020, 20:18 Henrik Bengtsson, 
>> wrote:
>>
>>> On Wed, May 20, 2020 at 11:10 AM brodie gaslam via R-devel
>>>  wrote:
>>> >
>>> >  > On Wednesday, May 20, 2020, 7:00:09 AM EDT, peter dalgaard <
>>> pda...@gmail.com> wrote:
>>> > >
>>> > > Expected, see FAQ 7.31.
>>> > >
>>> > > You just can't trust == on FP operations. Notice also
>>> >
>>> > Additionally, since you're implementing a "mean" function you are
>>> testing
>>> > against R's mean, you might want to consider that R uses a two-pass
>>> > calculation[1] to reduce floating point precision error.
>>>
>>> This one is important.
>>>
>>> FWIW, matrixStats::mean2() provides argument refine=TRUE/FALSE to
>>> calculate mean with and without this two-pass calculation;
>>>
>>> > a <- c(x[idx],y[idx],z[idx]) / 3
>>> > b <- mean(c(x[idx],y[idx],z[idx]))
>>> > b == a
>>> [1] FALSE
>>> > b - a
>>> [1] 2.220446e-16
>>>
>>> > c <- matrixStats::mean2(c(x[idx],y[idx],z[idx]))  ## default to
>>> refine=TRUE
>>> > b == c
>>> [1] TRUE
>>> > b - c
>>> [1] 0
>>>
>>> > d <- matrixStats::mean2(c(x[idx],y[idx],z[idx]), refine=FALSE)
>>> > a == d
>>> [1] TRUE
>>> > a - d
>>> [1] 0
>>> > c == d
>>> [1] FALSE
>>> > c - d
>>> [1] 2.220446e-16
>>>
>>> Not surprisingly, the two-pass higher-precision version (refine=TRUE)
>>> takes roughly twice as long as the one-pass quick version
>>> (refine=FALSE).
>>>
>>> /Henrik
>>>
>>> >
>>> > Best,
>>> >
>>> > Brodie.
>>> >
>>> > [1]
>>> https://github.com/wch/r-source/blob/tags/R-4-0-0/src/main/summary.c#L482
>>> >
>>> > > > a2=(z[idx]+x[idx]+y[idx])/3
>>> > > > a2==a
>>> > > [1] FALSE
>>> > > > a2==b
>>> > > [1] TRUE
>>> > >
>>> > > -pd
>>> > >
>>> > > > On 20 May 2020, at 12:40 , Morgan Morgan <
>>> morgan.email...@gmail.com> wrote:
>>> > > >
>>> > > > Hello R-dev,
>>> > > >
>>> > > > Yesterday, while I was testing the newly implemented function
>>> pmean in
>>> > > > package kit, I noticed a mismatch in the output of the below R
>>> expressions.
>>> > > >
>>> > > > set.seed(123)
>>> > > > n=1e3L
>>> > > > idx=5
>>> > > > x=rnorm(n)
>>> > > > y=rnorm(n)
>>> > > > z=rnorm(n)
>>> > > > a=(x[idx]+y[idx]+z[idx])/3
>>> > > > b=mean(c(x[idx],y[idx],z[idx]))
>>> > > > a==b
>>> > > > # [1] FALSE
>>> > > >
>>> > > > For idx= 1, 2, 3, 4 the last line is equal to TRUE. For 5, 6 and
>>> many
>>> > > > others the difference is small but still.
>>> > > > Is that expected or is it a bug?
>>> >
>>> > __
>>> > R-devel@r-project.org mailing list
>>> > https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Precision of function mean,bug?

2020-05-20 Thread Morgan Morgan
Hello R-dev,

Yesterday, while I was testing the newly implemented function pmean in
package kit, I noticed a mismatch in the output of the below R expressions.

set.seed(123)
n=1e3L
idx=5
x=rnorm(n)
y=rnorm(n)
z=rnorm(n)
a=(x[idx]+y[idx]+z[idx])/3
b=mean(c(x[idx],y[idx],z[idx]))
a==b
# [1] FALSE

For idx= 1, 2, 3, 4 the last line is equal to TRUE. For 5, 6 and many
others the difference is small but still.
Is that expected or is it a bug?

Thank you
Best Regards
Morgan Jacob

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] psum/pprod

2020-05-16 Thread Morgan Morgan
Good morning All,

Just wanted to do quick follow-up on this thread:
https://r.789695.n4.nabble.com/There-is-pmin-and-pmax-each-taking-na-rm-how-about-psum-td4647841.html

For those (including the R-core team) of you who are interested in a C
implementation of psum and pprod there is one in the "kit" package (I am
the author) on CRAN.

I will continue working on the package in my spare time if I see that users
are missing basic functionalities not implemented in base R.

Have a great weekend.
Kind regards
Morgan Jacob

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Hash functions at C level

2020-05-03 Thread Morgan Morgan
Dear R-dev,

Hope you are all well.
I would like to know if there is a hash function available for the R C API?
I noticed that there are hash structures and functions defined in the file
"unique.c". These would definitly suit my needs, however is there a way to
access them at C level?
Thank you for your time.
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Long vector support in data.frame

2020-01-23 Thread Morgan Morgan
Hi All,

Happy New Year!

I was wondering if there is a plan at some point to support long vectors in
data.frames?
I understand that it would need some internal changes to lift the current
limit.
If there is a plan what is currently preventing it from happening? Is it
time, resources? If so is there a way for people willing to help to
contribute or help the R-dev team? How?
I noticed that an increasing number of function are supporting long vectors
in base R. Is there more functions that need to support long vectors before
having long vectors support in data.frames?

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Aggregate function FR

2019-11-20 Thread Morgan Morgan
Hi,

I was wondering if it would be possible to add an argument to the aggreagte
function to retain NA by categories?(default can not to in order to avoid
breaking code) Please see below example:

df = iris
df$Species[5] = NA
aggregate(`Petal.Width` ~ Species, df, sum) # does not include NA
aggregate(`Petal.Width` ~ addNA(Species), df, sum) # include NA

data.table and dplyr include NA by default.
Python pandas has an aggreagate function inspired by base R aggregate. An
option has been added to include NA.

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Questions on the R C API

2019-11-04 Thread Morgan Morgan
Thank you for your reply Jiefei.
I think in theory your solution should work. I'll have to give them a try.


On Mon, 4 Nov 2019 23:41 Wang Jiefei,  wrote:

> Hi Morgan,
>
> My solutions might not be the best one(I believe it's not), but it should
> work for your question.
>
> 1. Have you considered Rf_duplicate function? If you want to change the
> value of `a` and reset it later, you have to have a duplication somewhere
> for resetting it. Instead of changing the value of `a` directly, why not
> changing the value of a duplicated `a`? So you do not have to reset it.
>
> 2. I think a pairlist behaves like a linked list(I might be wrong here and
> please correct me if so). Therefore, there is no simple way to locate an
> element in a pairlist. As for as I know, R defines a set of
> convenient functions for you to access a limited number of elements. See
> below
>
> ```
> #define CAR(e) ((e)->u.listsxp.carval)
> #define CDR(e) ((e)->u.listsxp.cdrval)
> #define CAAR(e) CAR(CAR(e))
> #define CDAR(e) CDR(CAR(e))
> #define CADR(e) CAR(CDR(e))
> #define CDDR(e) CDR(CDR(e))
> #define CDDDR(e) CDR(CDR(CDR(e)))
> #define CADDR(e) CAR(CDR(CDR(e)))
> #define CADDDR(e) CAR(CDR(CDR(CDR(e
> #define CAD4R(e) CAR(CDR(CDR(CDR(CDR(e)
> ```
>
> You can use them to get first a few arguments from a pairlist. Another
> solution would be converting the pairlist into a list so that you can use
> the methods defined for a list to access any element. I do not know which C
> function can achieve that but `as.list` at R level should be able to do
> this job, you can evaluate an R function at C level and get the list
> result( By calling `Rf_eval`). I think this operation is relatively low
> cost because the list should only contain a set of pointers pointing to
> each element. There is no object duplication(Again I might be wrong here).
>


So there is no way to reset a pairlist to its first element?


> 3. You can get unevaluated expression at the R level before you call the C
> function and pass it to your C function( by calling `substitute` function).
> However, from my vague memory, the expression would be eventually evaluated
> at the C level even you pass the expression to it. Therefore, I think you
> can create a list of unevaluated arguments before you enter the C function,
> so your C function can expect a list rather than a pairlist as its
> argument. This can solve both your second and third questions.
>

Correct me if I am wrong but does it mean that I will have to change "..."
to "list(...)" and use .Call instead of .External?

Also does it mean that to avoid expression to be evaluated at the R level,
I have to use "list" or "substitute"? The function "switch" in R does not
use them but manage to achieve that.

switch(1, "a", stop("a"))
#[1] "a"

It is a primitive but I don't understand how it manage to do that.

Best,
Morgan



> Best,
> Jiefei
>
>
> On Mon, Nov 4, 2019 at 2:41 PM Morgan Morgan 
> wrote:
>
>> Hi All,
>>
>> I have some questions regarding the R C API.
>>
>> Let's assume I have a function which is defined as follows:
>>
>> R file:
>>
>> myfunc <- function(a, b, ...) .External(Cfun, a, b, ...)
>>
>> C file:
>>
>> SEXP Cfun(SEXP args) {
>>   args = CDR(args);
>>   SEXP a = CAR(args); args = CDR(args);
>>   SEXP b = CAR(args); args = CDR(args);
>>   /* continue to do something with remaining arguments in "..." using the
>> same logic as above*/
>>
>>   return R_NilValue;
>> }
>>
>> 1/ Let's suppose that in my c function I change the value of a inside the
>> function but I want to reset it to what it was when I did SEXP a =
>> CAR(args); . How can I do that?
>>
>> 2/Is there a method to set "args" at a specific position so I can access a
>> specific value of my choice? If yes, do you have an simple example?
>>
>> 3/ Let's suppose now, I call the function in R. Is there a way to avoid
>> the
>> function to evaluate its arguments before going to the C call? Do I have
>> to
>> do it at the R level or can it be done at the C level?
>>
>> Thank you very much in advance.
>> Best regards
>> Morgan
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Questions on the R C API

2019-11-04 Thread Morgan Morgan
Hi All,

I have some questions regarding the R C API.

Let's assume I have a function which is defined as follows:

R file:

myfunc <- function(a, b, ...) .External(Cfun, a, b, ...)

C file:

SEXP Cfun(SEXP args) {
  args = CDR(args);
  SEXP a = CAR(args); args = CDR(args);
  SEXP b = CAR(args); args = CDR(args);
  /* continue to do something with remaining arguments in "..." using the
same logic as above*/

  return R_NilValue;
}

1/ Let's suppose that in my c function I change the value of a inside the
function but I want to reset it to what it was when I did SEXP a =
CAR(args); . How can I do that?

2/Is there a method to set "args" at a specific position so I can access a
specific value of my choice? If yes, do you have an simple example?

3/ Let's suppose now, I call the function in R. Is there a way to avoid the
function to evaluate its arguments before going to the C call? Do I have to
do it at the R level or can it be done at the C level?

Thank you very much in advance.
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] New matrix function

2019-10-11 Thread Morgan Morgan
Your answer makes much more sense to me.
I will probably end up adding the function to a package.
Some processes and decisions on how R is developed seems to be obscure to
me.

Thank you
Morgan

On Fri, 11 Oct 2019 15:30 Avraham Adler,  wrote:

> It’s rather difficult. For example, the base R Kendall tau is written with
> the naive O(n^2). The much faster O(n log n) implementation was programmed
> and is in the pcaPP package. When I say much faster, I mean that my
> implementation in Excel VBA was faster than R for 10,000 or so pairs.
> R-Core decided not to implement that code, and instead made a note about
> the faster implementation living in pcaPP in the help for “cor”. See [1]
> for the 2012 discussion. My point is it’s really really difficult to get
> something in Base R. Develop it well, put it in a package, and you have
> basically the same result.
>
> Avi
>
> [1] https://stat.ethz.ch/pipermail/r-devel/2012-June/064351.html
>
> On Fri, Oct 11, 2019 at 9:55 AM Morgan Morgan 
> wrote:
>
>> How do you prove usefulness of a feature?
>> Do you have an example of a feature that has been added after proving to
>> be
>> useful in the package space first?
>>
>> Thank you,
>> Morgan
>>
>> On Fri, 11 Oct 2019 13:53 Michael Lawrence, 
>> wrote:
>>
>> > Thanks for this interesting suggestion, Morgan. While there is no strict
>> > criteria for base R inclusion, one criterion relevant in this case is
>> that
>> > the usefulness of a feature be proven in the package space first.
>> >
>> > Michael
>> >
>> >
>> > On Fri, Oct 11, 2019 at 5:19 AM Morgan Morgan <
>> morgan.email...@gmail.com>
>> > wrote:
>> >
>> >> On Fri, 11 Oct 2019 10:45 Duncan Murdoch, 
>> >> wrote:
>> >>
>> >> > On 11/10/2019 6:44 a.m., Morgan Morgan wrote:
>> >> > > Hi All,
>> >> > >
>> >> > > I was looking for a function to find a small matrix inside a larger
>> >> > matrix
>> >> > > in R similar to the one described in the following link:
>> >> > >
>> >> > >
>> >> >
>> >>
>> https://www.mathworks.com/matlabcentral/answers/194708-index-a-small-matrix-in-a-larger-matrix
>> >> > >
>> >> > > I couldn't find anything.
>> >> > >
>> >> > > The above function can be seen as a "generalisation" of the "which"
>> >> > > function as well as the function described in the following post:
>> >> > >
>> >> > >
>> >> >
>> >>
>> https://coolbutuseless.github.io/2018/04/03/finding-a-length-n-needle-in-a-haystack/
>> >> > >
>> >> > > Would be possible to add such a function to base R?
>> >> > >
>> >> > > I am happy to work with someone from the R core team (if you wish)
>> and
>> >> > > suggest an implementation in C.
>> >> >
>> >> > That seems like it would sometimes be a useful function, and maybe
>> >> > someone will point out a package that already contains it.  But if
>> not,
>> >> > why would it belong in base R?
>> >> >
>> >>
>> >> If someone already implemented it, that would great indeed. I think it
>> is
>> >> a
>> >> very general and basic function, hence base R could be a good place for
>> >> it?
>> >>
>> >> But this is probably not a good reason; maybe someone from the R core
>> team
>> >> can shed some light on how they decide whether or not to include a
>> >> function
>> >> in base R?
>> >>
>> >>
>> >> > Duncan Murdoch
>> >> >
>> >>
>> >> [[alternative HTML version deleted]]
>> >>
>> >> __
>> >> R-devel@r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-devel
>> >>
>> >
>> >
>> > --
>> > Michael Lawrence
>> > Scientist, Bioinformatics and Computational Biology
>> > Genentech, A Member of the Roche Group
>> > Office +1 (650) 225-7760
>> > micha...@gene.com
>> >
>> > Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
> --
> Sent from Gmail Mobile
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] New matrix function

2019-10-11 Thread Morgan Morgan
I think you are confusing package and function here. Plus some of the R
Core packages, that you mention, contain functions that should probably be
replaced by functions with better implementation from packages on CRAN.

Best regards
Morgan

On Fri, 11 Oct 2019 15:22 Joris Meys,  wrote:

>
>
> On Fri, Oct 11, 2019 at 3:55 PM Morgan Morgan 
> wrote:
>
>> How do you prove usefulness of a feature?
>> Do you have an example of a feature that has been added after proving to
>> be
>> useful in the package space first?
>>
>> Thank you,
>> Morgan
>>
>
> The parallel package (a base package like utils, stats, ...) was added as
> a drop-in replacement of the packages snow and multicore for parallel
> computing. That's one example, but sure there's more.
>
> Kind regards
> Joris
>
> --
> Joris Meys
> Statistical consultant
>
> Department of Data Analysis and Mathematical Modelling
> Ghent University
> Coupure Links 653, B-9000 Gent (Belgium)
>
> <https://maps.google.com/?q=Coupure+links+653,%C2%A0B-9000+Gent,%C2%A0Belgium=gmail=g>
>
> ---
> Biowiskundedagen 2018-2019
> http://www.biowiskundedagen.ugent.be/
>
> ---
> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] New matrix function

2019-10-11 Thread Morgan Morgan
How do you prove usefulness of a feature?
Do you have an example of a feature that has been added after proving to be
useful in the package space first?

Thank you,
Morgan

On Fri, 11 Oct 2019 13:53 Michael Lawrence, 
wrote:

> Thanks for this interesting suggestion, Morgan. While there is no strict
> criteria for base R inclusion, one criterion relevant in this case is that
> the usefulness of a feature be proven in the package space first.
>
> Michael
>
>
> On Fri, Oct 11, 2019 at 5:19 AM Morgan Morgan 
> wrote:
>
>> On Fri, 11 Oct 2019 10:45 Duncan Murdoch, 
>> wrote:
>>
>> > On 11/10/2019 6:44 a.m., Morgan Morgan wrote:
>> > > Hi All,
>> > >
>> > > I was looking for a function to find a small matrix inside a larger
>> > matrix
>> > > in R similar to the one described in the following link:
>> > >
>> > >
>> >
>> https://www.mathworks.com/matlabcentral/answers/194708-index-a-small-matrix-in-a-larger-matrix
>> > >
>> > > I couldn't find anything.
>> > >
>> > > The above function can be seen as a "generalisation" of the "which"
>> > > function as well as the function described in the following post:
>> > >
>> > >
>> >
>> https://coolbutuseless.github.io/2018/04/03/finding-a-length-n-needle-in-a-haystack/
>> > >
>> > > Would be possible to add such a function to base R?
>> > >
>> > > I am happy to work with someone from the R core team (if you wish) and
>> > > suggest an implementation in C.
>> >
>> > That seems like it would sometimes be a useful function, and maybe
>> > someone will point out a package that already contains it.  But if not,
>> > why would it belong in base R?
>> >
>>
>> If someone already implemented it, that would great indeed. I think it is
>> a
>> very general and basic function, hence base R could be a good place for
>> it?
>>
>> But this is probably not a good reason; maybe someone from the R core team
>> can shed some light on how they decide whether or not to include a
>> function
>> in base R?
>>
>>
>> > Duncan Murdoch
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
> --
> Michael Lawrence
> Scientist, Bioinformatics and Computational Biology
> Genentech, A Member of the Roche Group
> Office +1 (650) 225-7760
> micha...@gene.com
>
> Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] New matrix function

2019-10-11 Thread Morgan Morgan
On Fri, 11 Oct 2019 10:45 Duncan Murdoch,  wrote:

> On 11/10/2019 6:44 a.m., Morgan Morgan wrote:
> > Hi All,
> >
> > I was looking for a function to find a small matrix inside a larger
> matrix
> > in R similar to the one described in the following link:
> >
> >
> https://www.mathworks.com/matlabcentral/answers/194708-index-a-small-matrix-in-a-larger-matrix
> >
> > I couldn't find anything.
> >
> > The above function can be seen as a "generalisation" of the "which"
> > function as well as the function described in the following post:
> >
> >
> https://coolbutuseless.github.io/2018/04/03/finding-a-length-n-needle-in-a-haystack/
> >
> > Would be possible to add such a function to base R?
> >
> > I am happy to work with someone from the R core team (if you wish) and
> > suggest an implementation in C.
>
> That seems like it would sometimes be a useful function, and maybe
> someone will point out a package that already contains it.  But if not,
> why would it belong in base R?
>

If someone already implemented it, that would great indeed. I think it is a
very general and basic function, hence base R could be a good place for it?

But this is probably not a good reason; maybe someone from the R core team
can shed some light on how they decide whether or not to include a function
in base R?


> Duncan Murdoch
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] New matrix function

2019-10-11 Thread Morgan Morgan
Hi All,

I was looking for a function to find a small matrix inside a larger matrix
in R similar to the one described in the following link:

https://www.mathworks.com/matlabcentral/answers/194708-index-a-small-matrix-in-a-larger-matrix

I couldn't find anything.

The above function can be seen as a "generalisation" of the "which"
function as well as the function described in the following post:

https://coolbutuseless.github.io/2018/04/03/finding-a-length-n-needle-in-a-haystack/

Would be possible to add such a function to base R?

I am happy to work with someone from the R core team (if you wish) and
suggest an implementation in C.

Thank you
Best regards,
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Evaluate part of an expression at C level

2019-09-27 Thread Morgan Morgan
Hi,

I am wondering if the below is possible?
Let's assume I have the following expression:

1:10 < 5

Is there a way at the R C API level to only evaluate the 5th element (i.e 5
< 5) instead of evaluating the whole expression and then select the 5th
element in the logical vector?

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Convert STRSXP or INTSXP to factor

2019-07-15 Thread Morgan Morgan
Hi,

Using the R C PAI, is there a way to convert to convert STRSXP or INTSXP to
factor.

The idea would be to do in C something similar to the "factor" function
(example below):

> letters[1:5]
# [1] "a" "b" "c" "d" "e"

> factor(letters[1:5])
# [1] a b c d e
# Levels: a b c d e

There is the function setAttrib the levels of a SXP however when returned
to R the object is of type character not factor. Ideally what i would like
to return from the C function is the same output as above when the input is
of type character.

Please let me if you need more informations.
Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] R C API resize matrix

2019-06-17 Thread Morgan Morgan
Hi,

Is there a way to resize a matrix defined as follows:

SEXP a = PROTECT(allocMatrix(INTSXP, 10, 2));
int *pa  = INTEGER(a)

To row = 5 and col = 1 or do I have to allocate a second matrix "b" with
pointer *pb and do a "for" loop to transfer the value of a to b?

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Package inclusion in R core implementation

2019-03-01 Thread Morgan Morgan
Hi,

It sometimes happens that some packages get included to R like for example
the parallel package.

I was wondering if there is a process to decide whether or not to include a
package in the core implementation of R?

For example, why not include the Rcpp package, which became for a lot of
user the main tool to extend R?

What is our view on the (not so well known) dotCall64 package which is an
interesting alternative for extending R?

Thank you
Best regards,
Morgan

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel