[Rd] anyNA() performance on vectors of POSIXct

2019-05-01 Thread Harvey Smith
Inside of the anyNA() function, it will use the legacy any(is.na()) code if
x is an OBJECT().  If x is a vector of POSIXct, it will be an OBJECT(), but
it is also TYPEOF(x) == REALSXP.  Therefore, it will skip the faster
ITERATE_BY_REGION, which is typically 5x faster in my testing.

Is the OBJECT() condition really necessary, or could it be moved after the
switch() for the individual TYPEOF(x) ITERATE_BY_REGION calls?

# script to demonstrate performance difference if x is an OBJECT or not by
using unclass()
x.posixct = Sys.time() + 1:1e6
microbenchmark::microbenchmark(
  any(is.na( x.posixct )),
  anyNA( x.posixct ),
  anyNA( unclass(x.posixct) ),
  unit='ms')



static Rboolean anyNA(SEXP call, SEXP op, SEXP args, SEXP env)
{
  SEXP x = CAR(args);
  SEXPTYPE xT = TYPEOF(x);
  Rboolean isList =  (xT == VECSXP || xT == LISTSXP), recursive = FALSE;

  if (isList && length(args) > 1) recursive = asLogical(CADR(args));
  *if (OBJECT(x) || (isList && !recursive)) {*
SEXP e0 = PROTECT(lang2(install("is.na"), x));
SEXP e = PROTECT(lang2(install("any"), e0));
SEXP res = PROTECT(eval(e, env));
int ans = asLogical(res);
UNPROTECT(3);
return ans == 1; // so NA answer is false.
  }

  R_xlen_t i, n = xlength(x);
  switch (xT) {
case REALSXP:
{
  if(REAL_NO_NA(x))
return FALSE;
  ITERATE_BY_REGION(x, xD, i, nbatch, double, REAL, {
for (int k = 0; k < nbatch; k++)
  if (ISNAN(xD[k]))
return TRUE;
  });
  break;
}

[[alternative HTML version deleted]]

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


Re: [Rd] [External] Re: Background R session on Unix and SIGINT

2019-05-01 Thread Simon Urbanek
Gabor,

I think you're talking about two independent things. You can interrupt the 
computation, no question about that. It's just that if you send an interrupt 
while you're *not* doing any computations, it will be signaled but not raised 
until the interrupts are checked since there is no one to check it. This goes 
back to my original response - the interactive REPL calls 
R_CheckUserInterrupt(), but the straight stdin-prcessing doesn't (since it's 
expected to be a script, not interactive prompt). If you just want to clear 
interrupts before next processing you can either just run 
R_CheckUserInterrupt() explicitly, or on R side do anything that does that, 
e.g. to take your example "tryCatch(Sys.sleep(0), interrupt = function(e) e)" 
will clear it.

Cheers,
Simon


> On Apr 30, 2019, at 7:03 PM, Gábor Csárdi  wrote:
> 
> Unfortunately --interactive also makes the session interactive(),
> which is bad for me, as it is a background session.
> 
> In general, I don't want the interactive behavior, but was wondering
> if I could send as SIGINT to try to interrupt the computation of the
> background process, and if that does not work, then I would send a
> SIGKILL and start up another process. It all works nicely, except for
> this glitch, but I think I can work around it.
> 
> Thanks,
> Gabor
> 
> On Tue, Apr 30, 2019 at 10:55 PM Tierney, Luke  wrote:
>> 
>> A Simon pointed out the interrupt is recorded but not processed until
>> a safe point.
>> 
>> When reading from a fifo or pipe R runs non-interactive, which means
>> is sits in a read() system call and the interrupt isn't seen until
>> sometime during evaluation when a safe checkpoint is reached.
>> 
>> When reading from a terminal R will use select() to wait for input and
>> periodically wake and check for interrupts. In that case the interrupt
>> will probably be seen sooner.
>> 
>> If the interactive behavior is what you want you can add --interactive
>> to the arguments used to start R.
>> 
>> Best,
>> 
>> luke
>> 
>> On Tue, 30 Apr 2019, Gábor Csárdi wrote:
>> 
>>> OK, I managed to create an example without callr, but it is still
>>> somewhat cumbersome. Anyway, here it is.
>>> 
>>> Terminal 1:
>>> mkfifo fif
>>> R --no-readline --slave --no-save --no-restore < fif
>>> 
>>> Terminal 2:
>>> cat > fif
>>> Sys.getpid()
>>> 
>>> This will make Terminal 1 print the pid of the R process, so we can
>>> send a SIGINT:
>>> 
>>> Terminal 3:
>>> kill -INT pid
>>> 
>>> The R process is of course still running happily.
>>> 
>>> Terminal 2 again:
>>> tryCatch(Sys.sleep(10), interrupt = function(e) e)
>>> 
>>> and then Terminal 1 prints the interrupt condition:
>>> 
>>> 
>>> This is macOS and 3.5.3, although I don't think it matters much.
>>> 
>>> Thanks much!
>>> G.
>>> 
>>> On Tue, Apr 30, 2019 at 9:50 PM Simon Urbanek
>>>  wrote:
 
 Can you give an example without callr? The key is how is the process 
 stated and what it is doing which is entirely opaque in callr.
 
 Windows doesn't have signals, so the process there is entirely different. 
 Most of the WIN32 processing is event-based.
 
 Cheers,
 Simon
 
 
> On Apr 30, 2019, at 4:17 PM, Gábor Csárdi  wrote:
> 
> Yeah, I get that they are async.
> 
> What happens is that the background process is not doing anything when
> the process gets a SIGINT. I.e. the background process is just
> listening on its standard input.
> 
> AFAICT for an interactive process such a SIGINT is just swallowed,
> with a newline outputted to the terminal.
> 
> But apparently, for this background process, it is not swallowed, and
> it is triggered later. FWIW it does not happen on Windows, not very
> surprisingly.
> 
> Gabor
> 
> On Tue, Apr 30, 2019 at 9:13 PM Simon Urbanek
>  wrote:
>> 
>> Interrupts are not synchronous in R - the signal only flags the request 
>> for interruption. Nothing actually happens until R_CheckUserInterrupt() 
>> is called at an interruptible point. In you case your code is apparently 
>> not calling R_CheckUserInterrupt() until later as a side-effect of the 
>> next evaluation.
>> 
>> Cheers,
>> Simon
>> 
>> 
>>> On Apr 30, 2019, at 3:44 PM, Gábor Csárdi  
>>> wrote:
>>> 
>>> Hi All,
>>> 
>>> I realize that this is not a really nice reprex, but anyone has an
>>> idea why a background R session would "remember" an interrupt (SIGINT)
>>> on Unix?
>>> 
>>> rs <- callr::r_session$new()
>>> rs$interrupt() # just sends a SIGINT
>>> #> [1] TRUE
>>> 
>>> rs$run(function() 1+1)
>>> #> Error: interrupt
>>> 
>>> rs$run(function() 1+1)
>>> #> [1] 2
>>> 
>>> It seems that the main loop somehow stores the SIGINT it receives
>>> while it is waiting on stdin, and then it triggers it when some input
>>> comes in Maybe. Just speculating
>>> 
>>> Thanks,
>>

Re: [Rd] [External] Re: Background R session on Unix and SIGINT

2019-05-01 Thread Gábor Csárdi
On Wed, May 1, 2019 at 4:20 PM Simon Urbanek
 wrote:
> I think you're talking about two independent things. You can interrupt the 
> computation, no question about that. It's just that if you send an interrupt 
> while you're *not* doing any computations, it will be signaled but not raised 
> until the interrupts are checked since there is no one to check it.

Right. That's what I suspected originally, so thank you both for
confirming it. The difficulty is, when I interrupt the computation
that's a race condition, because in the master process I have no idea
knowing whether the computation will be finished just before the
SIGINT arrives.

> This goes back to my original response - the interactive REPL calls 
> R_CheckUserInterrupt(), but the straight stdin-prcessing doesn't (since it's 
> expected to be a script, not interactive prompt). If you just want to clear 
> interrupts before next processing you can either just run 
> R_CheckUserInterrupt() explicitly, or on R side do anything that does that, 
> e.g. to take your example "tryCatch(Sys.sleep(0), interrupt = function(e) e)" 
> will clear it.

Yes, that's exactly what I am doing. Thanks again!

Gabor

[...]

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


Re: [Rd] Inno Setup 6.0.2 fails before creating exe file on Windows (R-3.6.0)

2019-05-01 Thread Jeroen Ooms
Multiple people have now reported that the R installer does not build
with InnoSetup 6 (released last week). The inno log shows this error:

  Error on line 12 in src\gnuwin32\installer\R.iss: Minimum NT version
specified by MinVersion must be at least 6.0. (Windows 2000/XP/Server
2003 are no longer supported.)
  Compile aborted.

Hence to fix this, the "MinVersion" parameter in
src/gnuwin32/installer/header1.iss should be increased from 0,5.0 to
0,6.0. I confirmed this resolves the problem. Could somebody commit
this please?

See also: http://www.jrsoftware.org/is6help/index.php?topic=setup_minversion



On Sun, Apr 28, 2019 at 11:07 AM Avraham Adler  wrote:
>
> I am working on compiling R-3.6.0 for Windows 10 64bit using rtools40
> (beta 11). I had also installed the most recent update of Inno setup,
> which is now 6.0.2.With that version, `make risntaller` fails at the
> call to ""C:/R/Inno/iscc" R.iss > R-3.6.0.log 2>&1" and just exits,
> pointing to line 175 of the makefile which is:
>
> $(RPREFIX)-win.exe: R.iss
> "$(ISDIR)/iscc" R.iss > $(RPREFIX).log 2>&1
>
> Reinstalling Inno Setup 5.6.1 does allow the exe file to be created.
>
> Thank you,
>
> Avi
>
> __
> 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