[Rd] NEWS vs. inst/NEWS

2018-07-06 Thread William Dunlap via R-devel
'Writing R Extensions', section 1.1.5, in the part about a package's 'inst' directory, says that if NEW is in both the top level and in the inst directory, the in inst will be installed: Note that with the exceptions of INDEX, LICENSE/LICENCE and NEWS, information files at the top level of the

[Rd] minor problem in XML package

2018-06-06 Thread William Dunlap via R-devel
[The package XML is labelled ORPHANED and a comment says the CRAN team maintains it. I am not sure what address to send this to.] In package XML version 3.98.1.11, RUtils.c registers the C function RS_XML_xmlNodeChildrenReferences twice. The registration information is identical but this could

Re: [R-pkg-devel] mvrnorm, eigen, tests, and R CMD check

2018-05-17 Thread William Dunlap
at give rise to the lack of > reproducibility > > across architectures. The choice of basis appears to use different > > heuristics on 32-bit windows than on 64-bit Windows or Linux machines. > As a > > result, I can't include the tests I'd like as part of a CRAN submission. > >

Re: [Rd] length of `...`

2018-05-03 Thread William Dunlap via R-devel
In R-3.5.0 you can use ...length(): > f <- function(..., n) ...length() > f(stop("one"), stop("two"), stop("three"), n=7) [1] 3 Prior to that substitute() is the way to go > g <- function(..., n) length(substitute(...())) > g(stop("one"), stop("two"), stop("three"), n=7) [1] 3

Re: [Rd] issue with model.frame()

2018-05-01 Thread William Dunlap via R-devel
You run into the same problem when using 'non-syntactical' names: > mfB <- model.frame(y ~ `Temp(C)` + `Pres(mb)`, data=data.frame(check.names=FALSE, y=1:10, `Temp(C)`=21:30, `Pres(mb)`=991:1000)) > match(attr(terms(mfB), "term.labels"), names(mfB)) # gives NA's [1] NA NA > attr(terms(mfB),

Re: [R-pkg-devel] How to write example results to a tempdir()?

2018-04-26 Thread William Dunlap
The withr package has a bunch of simple functions executing code in various contexts, e.g., in a given directory or with given options() settings: > withr::with_dir function (new, code) { old <- setwd(dir = new) on.exit(setwd(old)) force(code) } > withr::with_dir(tempdir(), getwd())

[Rd] disappearing tempdir()

2018-04-24 Thread William Dunlap via R-devel
Recent versions of Windows will remove empty directories from areas that Windows considers places for temporary files. It does not seem to matter how old they are; empty directories are found and removred c. once a day. I haven't seen any documentation on this feature but I think you can turn if

Re: [Rd] odd assignInNamespace / setGeneric interaction

2018-04-19 Thread William Dunlap via R-devel
oo many R startup tweaking > possibilities, notably via environment variables. > [e.g., the current ways to pre-determine the active .libPaths() in R, > and the fact the R calls R again during 'R CMD check' etc, > sometimes drives me crazy when .libPaths() become incompatible > for

[Rd] odd assignInNamespace / setGeneric interaction

2018-04-18 Thread William Dunlap via R-devel
A coworker got tired of having to type 'yes' or 'no' after quitting R: he never wanted to save the R workspace when quitting. So he added assignInNamespace lines to his .Rprofile file to replace base::q with one that, by default, called the original with save="no"..

Re: [Rd] strange warning: data() error?

2018-04-16 Thread William Dunlap via R-devel
data(package="survival") gives, in part, cgd Chronic Granulotomous Disease data cgd0 (cgd) Chronic Granulotomous Disease data colon Chemotherapy for Stage B/C colon cancer flchain Assay of serum free light chain for 7874

Re: [Rd] alpha transparency doesn't work for lines when xpd=TRUE

2018-04-16 Thread William Dunlap via R-devel
The problem occurs in the Windows GUI with the 'windows()' graphics device. In the following example the red diagonal line appears in 3 plots but not in the one with xpd=TRUE and alpha.f=0.9. > par(mfrow=c(2,2)) > for(xpd in c(FALSE, TRUE)) for(alpha.f in c(.9, 1))

[R-pkg-devel] reg.finalizer and .onUnload

2018-03-21 Thread William Dunlap
I have a package that lets a user log into another system and I want it to be sure to log the user out, at least by the time the R session is over. My Login(username,password) function stashes a token (the username in my simplfied code) in an environment and my Logout() function needs to use that

Re: [Rd] backquotes and term.labels

2018-03-05 Thread William Dunlap via R-devel
I believe this has to do terms() making "term.labels" (hence the dimnames of "factors") with deparse(), so that the backquotes are included for non-syntactic names. The backquotes are not in the column names of the input data.frame (nor model frame) so you get a mismatch when subscripting the

Re: [Rd] readLines interaction with gsub different in R-dev

2018-02-17 Thread William Dunlap via R-devel
I think the problem in R-devel happens when there are non-ASCII characters in any of the strings passed to gsub. txt <- vapply(list(as.raw(c(0x41, 0x6d, 0xc3, 0xa9, 0x6c, 0x69, 0x65)), as.raw(c(0x41, 0x6d, 0x65, 0x6c, 0x69, 0x61))), rawToChar, "") txt #[1] "Amélie" "Amelia" Encoding(txt) #[1]

[Rd] Trailing underscores on C function names

2018-02-07 Thread William Dunlap via R-devel
In the fastmatch package, version 1.1-0, there is a C function called "ctapply_", with a trailing underscore. However, the NAMESPACE's call to useDynLib refers to "ctapply", without the trailing underscore. % grep ctapply NAMESPACE {R,src}/* NAMESPACE:useDynLib(fastmatch, C_fmatch = fmatch,

Re: [Rd] R-gui sessions end when executing C-code

2018-02-02 Thread William Dunlap via R-devel
SEXP eta = PROTECT(allocVector(REALSXP,H_c)); n_prot++; double *eta_c; eta_c = REAL(eta); for (i=0;i

Re: [R-pkg-devel] Working with R-devel

2018-01-24 Thread William Dunlap
On Linux you can trace all the getenv calls with ltrace. It only works on ELF files, not sh scripts: % R CMD ltrace -e getenv `R RHOME`/bin/*/R libR.so->getenv("R_HOME") = "/home/R/R-3.4.3/lib64/R" libR.so->getenv("R_TRANSLATIONS") = nil

Re: [Rd] as.character(list(NA))

2018-01-22 Thread William Dunlap via R-devel
> From: R-devel [mailto:r-devel-boun...@r-project.org] On Behalf Of Hervé > Pagès > Sent: Monday, January 22, 2018 2:01 PM > To: William Dunlap <wdun...@tibco.com>; Patrick Perry < > ppe...@stern.nyu.edu> > Cc: r-devel@r-project.org > Subject: Re: [Rd] as.char

Re: [Rd] as.character(list(NA))

2018-01-20 Thread William Dunlap via R-devel
I believe that for a list as.character() applies deparse() to each element of the list. deparse() does not preserve NA-ness, as it is intended to make text that the parser can read. > str(as.character(list(Na=NA, LglVec=c(TRUE,NA), Function=function(x){x+1}))) chr [1:3] "NA" "c(TRUE, NA)"

Re: [Rd] Fwd: R/MKL Intel 2018 Compatibility

2018-01-08 Thread William Dunlap via R-devel
The x and y passed to dgemm in that code are pointers to the same memory, thus breaking Fortran's no-aliasing rule. Is it possible the MKL depends on the caller following that rule? You might try dsyrk() instead of dgemm. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jan 8, 2018 at 6:57

Re: [R-pkg-devel] Assignments to the Global environment

2018-01-07 Thread William Dunlap
I think that assigning something to parent.frame() is bad practice, for the same reasons that assigning to .GlobalEnv is bad. You could instead make an environment in your package called, say, "TSEtools.env", with TSETools.env <- new.env() in some *.R file in the package's R directory.

Re: [Rd] silent recycling in logical indexing

2018-01-04 Thread William Dunlap via R-devel
I have never used this construct. However, part of my job is seeing how well CRAN packages work in our reimplementation of the R language and I am continually surprised by the inventiveness of package writers. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jan 4, 2018 at 1:44 PM, Ben

Re: [Rd] silent recycling in logical indexing

2018-01-04 Thread William Dunlap via R-devel
One use case is when you want to extract every third item, starting with the second, of an arbitrary vector with x[c(FALSE, TRUE, FALSE)] instead of x[seq_along(x) %% 3 == 2] Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jan 4, 2018 at 11:56 AM, Ben Bolker

Re: [Rd] winbuilder warning message wrt function pointers

2017-12-29 Thread William Dunlap via R-devel
, bsize, bmat, rmat, nfrail, y); } Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Dec 29, 2017 at 8:48 AM, William Dunlap <wdun...@tibco.com> wrote: > Try changing > static void (*fun)() = NULL; > to > DL_FUNC fun = NULL; > > Bill Dunlap > TIBCO Software > wdu

Re: [Rd] winbuilder warning message wrt function pointers

2017-12-29 Thread William Dunlap via R-devel
Try changing static void (*fun)() = NULL; to DL_FUNC fun = NULL; Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Dec 29, 2017 at 5:14 AM, Therneau, Terry M., Ph.D. < thern...@mayo.edu> wrote: > I've recently updated the coxme package, which calls internal routines > from the bdsmatrix

Re: [Rd] Wish List: base::source() + Add Execution Time Argument

2017-12-21 Thread William Dunlap via R-devel
Is source() the right place for this? It may be, but we've had customers who would like this sort of thing done for commands entered by hand. And there are those who want a description of any "non-triivial" objects created in .GlobalEnv by each expression, ... Do they need a way to wrap each

Re: [Rd] tryCatch in on.exit()

2017-12-01 Thread William Dunlap via R-devel
ing") #[error] caught simpleError/error/condition : pb. in f0's on.exit #[1] "[error] caught simpleError/error/condition : pb. in f0's on.exit" catch(f1) # calls stop(conditionObject) #[error] caught simpleError/error/condition : pb. in f1's on.exit #[1] "[error] caught simpleError/err

[Rd] tryCatch in on.exit()

2017-12-01 Thread William Dunlap via R-devel
The following example involves a function whose on.exit() expression both generates an error and catches the error. The body of the function also generates an error. When calling the function wrapped in a tryCatch, should that tryCatch's error function be given the error from the body of the

Re: [R-pkg-devel] Exited with status -1073741819.

2017-11-29 Thread William Dunlap
You wrote Exited with status -1073741819. The low byte of that status code is 5, which I think means a segmentation fault - reading or writing an address that you do not have permission of use. > as.hexmode(-1073741819) [1] "c005" If your code uses memory that it has not allocated it

Re: [Rd] check does not check that package examples remove tempdir()

2017-11-08 Thread William Dunlap via R-devel
's a plan to make check = TRUE the default though. > > /Henrik > > On Wed, Nov 8, 2017 at 4:43 PM, William Dunlap via R-devel > <r-devel@r-project.org> wrote: > > I was looking at the CRAN package 'bfork-0.1.2', which exposes the Unix > > fork() and waitpid() calls

[Rd] check does not check that package examples remove tempdir()

2017-11-08 Thread William Dunlap via R-devel
I was looking at the CRAN package 'bfork-0.1.2', which exposes the Unix fork() and waitpid() calls at the R code level, and noticed that the help file example for bfork::fork removes R's temporary directory, the value of tempdir(). I think it happens because the forked process shares the value

Re: [Rd] Extreme bunching of random values from runif with Mersenne-Twister seed

2017-11-03 Thread William Dunlap via R-devel
This issue was > discovered completely by chance when the output of the API was observed to > be highly non-random. It is possible that it is a 1/10^8 chance, but that > is hard to believe, given that the API hit depends on user input. Note also > that the issue goes away when we us

Re: [Rd] Extreme bunching of random values from runif with Mersenne-Twister seed

2017-11-03 Thread William Dunlap via R-devel
The random numbers in a stream initialized with one seed should have about the desired distribution. You don't win by changing the seed all the time. Your seeds caused the first numbers of a bunch of streams to be about the same, but the second and subsequent entries in each stream do look

Re: [Rd] Cannot Compute Box's M (Three Days Trying...)

2017-10-27 Thread William Dunlap via R-devel
Does it work if you supply the closing parenthesis on the call to boxM? The parser says the input is incomplete and a missing closing parenthesis would cause that error.. // create a string command with that variable name.String boxVariable = "boxM(boxMVariable [,-5], boxMVariable[,5]"; // try

Re: [Rd] uniform sampling without replacement algorithm

2017-10-18 Thread William Dunlap via R-devel
Splus used a similar method for sampling from "bigdata" objects. One problem was that sample() is used both for creating a sample and for scrambling the order of a vector. Scrambling the order of a big vector wastes time. It would be nice to be able to tell sample() that we don't care about the

Re: [Rd] file.copy(from=Directory, to=File) oddity

2017-09-11 Thread William Dunlap via R-devel
Bug 17337. Note that I get R making the zero-length file on both Windows and Linux, but the return values are different. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Sep 11, 2017 at 7:01 AM, Martin Maechler <maech...@stat.math.ethz.ch > wrote: > >>>>> Willi

[Rd] file.copy(from=Directory, to=File) oddity

2017-09-08 Thread William Dunlap via R-devel
When I mistakenly use file.copy() with a directory for the 'from' argument and a non-directory for the 'to' and overwrite=TRUE, file.copy returns FALSE, meaning it could not do the copying. However, it also replaces the 'to' file with a zero-length file. dir.create( fromDir <- tempfile() )

[Rd] arithmetic with zero-column data.frames

2017-08-08 Thread William Dunlap via R-devel
Should arithmetic operations work on zero-column data.frames (returning a zero-column data.frame with the same number of rows as the data.frame argument(s))? Currently we get: > 1 + data.frame(row.names=c("A","B")) Error in data.frame(value, row.names = rn, check.names = FALSE, check.rows =

Re: [Rd] force promises inside lapply

2017-07-31 Thread William Dunlap via R-devel
te(y), substitute(y))) >[[1]] >[[1]][[1]] >y > >[[1]][[2]] >X[[1L]] > > in any case, the lesson seems to be that quote and substitute are not > interchangeable, even though for example > >> (function() identical(quote({a}), substitute({a})))() >

Re: [Rd] force promises inside lapply

2017-07-29 Thread William Dunlap via R-devel
; > Now for the context my question arose in: given a function > >loader <- function(package, quietly = TRUE) { > >wrapper <- if (quietly) suppressPackageStartupMessages else `{` > >expr <- substitute(wrapper(library(package = package))) > &g

Re: [Rd] force promises inside lapply

2017-07-28 Thread William Dunlap via R-devel
1: substitute(), when given an argument to a function (which will be a promise) gives you the unevaluated expression given as the argument: > L <- list(a=1, b=2, c=3) > str(lapply(L, function(x) substitute(x))) List of 3 $ a: language X[[i]] $ b: language X[[i]] $ c: language X[[i]] The 'X'

[Rd] matrices with names

2017-07-20 Thread William Dunlap via R-devel
How should R deal with matrices that have a 'names' attribute? S (and S+) did not allow an object to have both dims and names but R does. However, some R functions copy the dims but not the names to the returned value and some copy both. I don't see a pattern to it. Is there a general rule for

Re: [Rd] 'do.call' appears to show inconsistent behavior for arguments of format "pkg::fun"

2017-07-10 Thread William Dunlap via R-devel
>The function Rmpi::mpi.bcast.cmd() calls eventually something along the lines of > >> scmd <- scmd <- substitute(cmd) >> arg <- list(...) >> scmd.arg <-serialize(list(scmd=scmd, arg=arg), NULL) >> if (length(scmd.arg$args) > 0) >>do.call(as.character(scmd.arg$scmd), scmd.arg$args, envir =

[Rd] attributes on symbols

2017-07-06 Thread William Dunlap via R-devel
The multcomp package has code in multcomp:::expression2coef that attaches the 'coef' attribute to symbols. Since there is only one symbol object in a session with a given name, this means that this attaching has a global effect. Should this be quietly allowed or should there be a warning or an

Re: [Rd] R history: Why 'L; in suffix character ‘L’ for integer constants?

2017-06-16 Thread William Dunlap via R-devel
re wdunlap tibco.com On Fri, Jun 16, 2017 at 11:53 AM, peter dalgaard <pda...@gmail.com> wrote: > > Wikipedia claims that C ints are still only guaranteed to be at least 16 bits, and longs are at least 32 bits. So no, R's integers are long. > > -pd > > > On 16 Jun 2017, at

Re: [Rd] R history: Why 'L; in suffix character ‘L’ for integer constants?

2017-06-16 Thread William Dunlap via R-devel
But R "integers" are C "ints", as opposed to S "integers", which are C "long ints". (I suppose R never had to run on ancient hardware with 16 bit ints.) Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jun 16, 2017 at 10:47 AM, Yihui Xie wrote: > Yeah, that was what I

Re: [Rd] spurious warning in ave()

2017-06-14 Thread William Dunlap via R-devel
You can avoid the warnings and the unneeded calls to FUN by adding drop=TRUE to the call to ave(), since all of its ... arguments are passed to interaction (I think). In TERR we dealt with this problem by adding drop=TRUE to ave's argument list and we pass ... and drop=drop to interaction. I'm

Re: [Rd] [WISH / PATCH] possibility to split string literals across multiple lines

2017-06-14 Thread William Dunlap via R-devel
If you are changing the parser (which is a major change) you might consider treating strings in the C/C++ way: char *s = "A" "B"; means the same as char *s = "AB"; I am not a big fan of that syntax but it is widely used. A backslash at the end of the line leads to errors

Re: [Rd] stopifnot() does not stop at first non-TRUE argument

2017-05-19 Thread William Dunlap via R-devel
While you are fiddling with stopifnot(), please consider changing the form of the error thrown so that it includes the caller's call. The change would be from something like stop( <> ) to stop(simpleError( <>, sys.call(-1))) For the following code f <- function(x, y) { stopifnot(x >

Re: [Rd] R-3.3.3/R-3.4.0 change in sys.call(sys.parent())

2017-05-11 Thread William Dunlap via R-devel
gt; wrote: > On Wed, May 10, 2017 at 2:36 AM, William Dunlap via R-devel > <r-devel@r-project.org> wrote: > > Some formula methods for S3 generic functions use the idiom > > returnValue$call <- sys.call(sys.parent()) > > to show how to recreate the returned object or to

Re: [Rd] tempdir() may be deleted during long-running R session

2017-04-26 Thread William Dunlap via R-devel
9-4973 > IM: bgpbraverock > > On Wed, 2017-04-26 at 08:25 -0700, William Dunlap via R-devel wrote: > > The Ubuntu machine I use a lot (along with others) must not be > > cleaning > > /tmp as it has a fair number of Rtmp* directories in /tmp, even when > > the

Re: [Rd] tempdir() may be deleted during long-running R session

2017-04-26 Thread William Dunlap via R-devel
The Ubuntu machine I use a lot (along with others) must not be cleaning /tmp as it has a fair number of Rtmp* directories in /tmp, even when there are no R sessions running on the machine. I would like to automate their removal but there is no obvious way to see if the R process that created the

[Rd] R_CMethodDef incompatibility (affects R_registerRoutines)

2017-04-25 Thread William Dunlap via R-devel
I recently noticed a change between R-3.3.3 and R-3.4.0 in the definition of the R_CMethodDef struct. typedef struct { const char *name; DL_FUNC fun; int numArgs; - R_NativePrimitiveArgType *types; - R_NativeArgStyle *styles; - } R_CMethodDef; I

Re: [Rd] system/system2 and open file descriptors

2017-04-20 Thread William Dunlap via R-devel
In S+ on Unix-alikes we dealt with this issue by using fcntl(fd, F_SETFD, 1) to set the close-on-exec flag on a file descriptor as soon as we opened it. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Apr 19, 2017 at 8:40 PM, Winston Chang wrote: > In addition to

Re: [Rd] A trap for young players with the lapply() function.

2017-03-28 Thread William Dunlap via R-devel
>I think that the suggestion I made, in response to a posting by Barry >>Rowlingson, that the first argument of lapply() be given the name of ".X" >rather >than just-plain-X, would be (a) effective, and (b) harmless. It would break any call to *apply() that used X= to name the first argument.

Re: [Rd] outer not applying a constant function

2017-03-20 Thread William Dunlap via R-devel
> Or is this a bad idea? I don't like the proposal. I have seen code like the following (in fact, I have written such code, where I had forgotten a function was not vectorized) where the error would have been discovered much later if outer() didn't catch it. > outer(1:3, 11:13, sum) Error

Re: [Rd] Fwd: Possible memory problems with mallloc when called with .C()

2017-03-20 Thread William Dunlap via R-devel
> void dnk_c(double *sortedFsample, unsigned long int n, unsigned long int k, double *dKol) All arguments to C functions called by .C() must be pointers. Also, R integers are C ints, not unsigned long ints. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Mar 20, 2017 at 5:55 AM, Hristo

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
>>> and binary calls. Namely higher than all the binary operators (except >>> for `:`), but lower than the other unary operators. Even if we gave >>> unary specials their own precedence I think it would end up in the >>> same place. >>> >>> `%l

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
ecture on my part. > > Best, > ~G > > On Fri, Mar 17, 2017 at 12:53 PM, William Dunlap <wdun...@tibco.com> wrote: >> >> Your example >>x = 5 >>exp = parse(text="f(uq(x)) + y +z") # expression: f(uq(x)) +y + z >>do_

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
; would have expected. I'm confused by this given what I understand the > purpose to be, but that probably just means I'm not the right person to ask. > > Hope that helps. > > Best, > ~G > > > > > > > > > > > On Fri, Mar 17, 2017 at 8:55 AM, William D

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
precedence I think it would end up in the >> same place. >> >> `%l%` <- function(x) tail(x, n = 1) >> %l% 1:5 >> #> [1] 5 >> %l% -5:-10 >> #> [1] -10 >> >> On Thu, Mar 16, 2017 at 6:57 PM, William Dunlap <wdu

Re: [Rd] Support for user defined unary functions

2017-03-16 Thread William Dunlap via R-devel
I am biased against introducing new syntax, but if one is experimenting with it one should make sure the precedence feels right. I think the unary and binary minus-sign operators have different precedences so I see no a priori reason to make the unary and binary %xxx% operators to be the same.

Re: [R-pkg-devel] Solaris SPARC, Fortran, and logical errors?

2017-03-15 Thread William Dunlap
I don't know about the current Sparc Fortran compilers, but over the years have learned not to try to pass logicals and character strings between C and Fortran. I have seen Fortran compilers that treated integer -1 (all bits 1) as .true. and anything else as .false. and I have see ones that

[Rd] simplify2array(higher=TRUE, listOfSingleRowDataframes)

2017-03-13 Thread William Dunlap via R-devel
I noticed that simplify2array acted oddly when given a list of data.frames of various sizes. If the data.frames have one row, it makes a new first dimension with the dimname equal to rownames(firstDataframe). That dimension does not appear for data.frames with other numbers of rows. >

Re: [Rd] Error in formatDL(nm, txt, indent = max(nchar(nm, "w")) + 3)

2017-03-09 Thread William Dunlap via R-devel
something reasonable when the 'indent' argument was too big. Changing if (indent > width/2) stop("incorrect values of 'indent' and 'width'") to indent <- min(indent, width/2) seems reasonable to me. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 9, 2017 at 7:2

Re: [Rd] Error in formatDL(nm, txt, indent = max(nchar(nm, "w")) + 3)

2017-03-09 Thread William Dunlap via R-devel
This error can arise when getOption("width") is too small. 80 seems to be the limit for me with R-3.3.2 on Windows. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 8, 2017 at 10:28 PM, Spencer Graves wrote: > Hello: > > > I tried "debug(help)" with

Re: [Rd] can we override "if" in R?

2017-03-05 Thread William Dunlap via R-devel
Da Zheng would like to override 'if' and 'while' to accept more than scalar logicals and Martin Maechler would like to change 'if' to accept only scalar logicals. No one has mentioned '||' and '&&', which also want scalar logicals. Perhaps a solution is to have all of these call a new generic

Re: [Rd] can we override "if" in R?

2017-03-04 Thread William Dunlap via R-devel
dplyr::translate_sql() redefines lots of functions, include "if", to translate from R syntax to SQL syntax. > dplyr::translate_sql(if ("mpg">25) "better" else "worse") CASE WHEN ('mpg' > 25.0) THEN ('better') ELSE ('worse') END Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Mar 4, 2017

Re: [Rd] Grapics Device Resolution Limits

2017-02-10 Thread William Dunlap via R-devel
Were you suppressing warnings? I get a warning along with the "unable to start device 'png'" in some cases where it fails. E.g., on Linux > png("Figure1A.png", h = 7, w = 7, res = 1e5, units = "cm") Error in png("Figure1A.png", h = 7, w = 7, res = 1e+05, units = "cm") : unable to start device

Re: [Rd] issue with unz()?

2017-02-09 Thread William Dunlap via R-devel
If you use check.names=FALSE in your call to read.csv you can see that the first column name starts with the 3 bytes ef bb bf, which is the UTF-8 "byte-order mark" that Microsoft applications like to put at the start of a text file stored in UTF-8. > v0514 <- read.csv(unz(temp, file0514[1]),

Re: [R-pkg-devel] TryCatch messages

2017-02-03 Thread William Dunlap
Use conditonMessage() to extract the message from an error, warning, message, or other 'condition' For more, see Hadley Wickham's book, "Advanced R": http://adv-r.had.co.nz/Exceptions-Debugging.html http://adv-r.had.co.nz/beyond-exception-handling.html Bill Dunlap TIBCO Software wdunlap

Re: [Rd] Undefined behavior of head() and tail() with n = 0

2017-01-26 Thread William Dunlap via R-devel
In addition, signed zeroes only exist for floating point numbers - the bit patterns for as.integer(0) and as.integer(-0) are identical. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jan 26, 2017 at 1:53 AM, Martin Maechler wrote: >> Florent Angly

Re: [Rd] RFC: tapply(*, ..., init.value = NA)

2017-01-26 Thread William Dunlap via R-devel
It would be cool if the default for tapply's init.value could be FUN(X[0]), so it would be 0 for FUN=sum or FUN=length, TRUE for FUN=all, -Inf for FUN=max, etc. But that would take time and would break code for which FUN did not work on length-0 objects. Bill Dunlap TIBCO Software wdunlap

Re: [Rd] How to handle INT8 data

2017-01-20 Thread William Dunlap via R-devel
If these are identifiers, store them as strings. If not, what sort of calculations do you plan on doing with them? Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jan 20, 2017 at 6:33 AM, Nicolas Paris wrote: > Hello r users, > > I have to deal with int8 data with

Re: [R-pkg-devel] Weird MAKEFLAGS bug

2017-01-10 Thread William Dunlap
MAKEFLAGS='CXXFLAGS=-std=c++0x -O2' R CMD SHLIB passes two items, 'CXXFLAGS=-std=c++0x' and '-O2', not the single item 'CXXFLAG=-std=c++0x -O2', to make. Suitably recent versions of GNU make take the make argument -O2 to control the 'output-sync'. Bill Dunlap TIBCO Software wdunlap tibco.com

[Rd] strsplit(perl=TRUE), gregexpr(perl=TRUE) very slow for long strings

2017-01-05 Thread William Dunlap via R-devel
While doing some speed testing I noticed that in R-3.2.3 the perl=TRUE variants of strsplit() and gregexpr() took time proportional to the square of the number of pattern matches in their input strings. E.g., the attached test function times gsub, strsplit, and gregexpr, with perl TRUE (PCRE) and

Re: [R-pkg-devel] accessing data by packagename::dataname from within package code fails.

2016-12-12 Thread William Dunlap
You can define the data in the R directory. You can keep it all in a *.R file by wrapping the text of the *.csv file in quotes and using read.table(text="quoted stuff"), as in: theData <- read.csv(header=TRUE, text=" English,Digit One,1 Two,2 Three,3") N <- nrow(theData) You need to make sure

Re: [Rd] [R-pkg-devel] accessing data by packagename::dataname from within package code fails.

2016-12-12 Thread William Dunlap via R-devel
You can define the data in the R directory. You can keep it all in a *.R file by wrapping the text of the *.csv file in quotes and using read.table(text="quoted stuff"), as in: theData <- read.csv(header=TRUE, text=" English,Digit One,1 Two,2 Three,3") N <- nrow(theData) You need to make sure

Re: [R-pkg-devel] Using BLAS on Windows

2016-11-10 Thread William Dunlap
The MGGM package has the following in src/Makevars.win to tell the linker to link with the Lapack, BLAS, and Fortran libraries. PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) Its Makevars file is identical - is that Makevars.win really needed? I don't see Makevars or Makevars.win in your

Re: [Rd] as.formula("x") error on C stack limit

2016-11-01 Thread William Dunlap via R-devel
Another example uses formula.character's other arguments: > as.formula("env") Error: object of type 'special' is not subsettable > as.formula("...") Error in eval(expr, envir, enclos) : '...' used in an incorrect context It may happen for the same reason that the following does not give an

Re: [R-pkg-devel] environment scoping

2016-10-27 Thread William Dunlap
If I were writing a package for factoring integers I might store a vector of known primes in an environment in my package and have my factoring functions append to the list when they find some more primes. This works because there is only one set of of primes (given we stick with ordinary

Re: [R-pkg-devel] Only printing a message once per top-level call.

2016-10-24 Thread William Dunlap
This is not a complete answer to your problem, but here is an example of how to make and store messages of a certain class, "lowMessage", and later print a table of the messages and their counts. > lowMessage <- function(text, call = sys.call(-1)) { # make a message of class

Re: [Rd] anonymous function parsing bug?

2016-10-21 Thread William Dunlap via R-devel
Here is a simplified version of your problem > { sqrt }(c(2,4,8)) [1] 1.414214 2.00 2.828427 Do you want that to act differently? Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 21, 2016 at 6:10 AM, Wilm Schumacher wrote: > Hi, > > I hope this is

Re: [R-pkg-devel] win-builder, compiling C code, make[1]: ar: Command not found

2016-10-07 Thread William Dunlap
wrote: > > It’s solved! Changing ‘ar’ to ‘$(AR)’ in the Makefile along with adding > AR="$(AR)" to @(cd libmseed && $(MAKE) static CC="$(CC)" > CFLAGS="$(CFLAGS)") in the Makevars.win fixed the problem. > > Thank you! > Gillian Sharer &g

Re: [R-pkg-devel] win-builder, compiling C code, make[1]: ar: Command not found

2016-10-07 Thread William Dunlap
Do you have a Makefile in the directory yourPackage/src/libmseed? If so, how does it call 'ar' or '$(AR)'? Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 7, 2016 at 3:44 PM, Gillian Sharer wrote: > Thank you for your response. I apologize for asking basic

Re: [Rd] error handling in strcapture

2016-10-04 Thread William Dunlap via R-devel
TRUE/FALSE needed > > > > > > Bill Dunlap > > TIBCO Software > > wdunlap tibco.com > > > > On Wed, Sep 21, 2016 at 2:32 PM, Michael Lawrence > > <lawrence.mich...@gene.com> wrote: > >> > >> The new behavior is that

Re: [Rd] error handling in strcapture

2016-10-04 Thread William Dunlap via R-devel
; wrote: > The new behavior is that it yields NAs when the pattern does not match > (like strptime) and for empty captures in a matching pattern it yields > the empty string, which is consistent with regmatches(). > > Michael > > On Wed, Sep 21, 2016 at 2:21 PM, William Dunlap <wd

Re: [Rd] suggested addition to model.matrix

2016-10-04 Thread William Dunlap via R-devel
In addition, there is a formula method for data.frame that assumes the first column is the dependent variable. > z <- data.frame(X1=1:6,X2=letters[1:3],Y=log(1:6)) > formula(z) X1 ~ X2 + Y > colnames(model.matrix(formula(z), z)) [1] "(Intercept)" "X2b" "X2c" "Y" Spencer's

Re: [Rd] Undocumented 'use.names' argument to c()

2016-09-23 Thread William Dunlap via R-devel
In Splus c() and unlist() called the same C code, but with a different 'sys_index' code (the last argument to .Internal) and c() did not consider an argument named 'use.names' special. > c function(..., recursive = F) .Internal(c(..., recursive = recursive), "S_unlist", TRUE, 1) > unlist

Re: [Rd] error handling in strcapture

2016-09-21 Thread William Dunlap via R-devel
Lawrence <lawrence.mich...@gene.com > wrote: > Hi Bill, > > Thanks, another good suggestion. strcapture() now returns NAs for > non-matches. It's nice to have someone kicking the tires on that > function. > > Michael > > On Wed, Sep 21, 2016 at 12:11 PM, Willia

[Rd] error handling in strcapture

2016-09-21 Thread William Dunlap via R-devel
Michael, thanks for looking at my first issue with utils::strcapture. Another issue is how it deals with lines that don't match the pattern. Currently it gives an error > strcapture("(.+) (.+)", c("One 1", "noSpaceInLine", "Three 3"), proto=list(Name="", Number=0)) Error in strcapture("(.+)

[Rd] strcapture enhancement

2016-09-21 Thread William Dunlap via R-devel
The new strcapture function in R-devel is handy, capturing the matches to the parenthesized subpatterns in a regular expression in the columns of a data.frame, whose column names and classes are given by the 'proto' argument. E.g., > p1 <- data.frame(Name="", Number=0) >

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread William Dunlap via R-devel
m> > wrote: > > The same argument would hold for tan(pi/2). > > I don't say the result 'NaN' is wrong, > > but I thought, > > tan(pi*x) and tanpi(x) should give the same result. > > > > Hans Werner > > > > > > On Fri, Sep 9, 2016 at 8

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread William Dunlap via R-devel
aN' is wrong, > but I thought, > tan(pi*x) and tanpi(x) should give the same result. > > Hans Werner > > > On Fri, Sep 9, 2016 at 8:44 PM, William Dunlap <wdun...@tibco.com> wrote: > > It should be the case that tan(pi*x) != tanpi(x) in many cases - that is > why &g

Re: [Rd] Different results for tan(pi/2) and tanpi(1/2)

2016-09-09 Thread William Dunlap via R-devel
It should be the case that tan(pi*x) != tanpi(x) in many cases - that is why it was added. The limits from below and below of the real function tan(pi*x) as x approaches 1/2 are different, +Inf and -Inf, so the limit is not well defined. Hence the computer function tanpi(1/2) ought to return

Re: [Rd] R (development) changes in arith, logic, relop with (0-extent) arrays

2016-09-08 Thread William Dunlap via R-devel
E, as is all(numeric()>0), by de Morgan's rule, but that is not really relevant here. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Sep 8, 2016 at 10:22 AM, Gabriel Becker <gmbec...@ucdavis.edu> wrote: > > > On Thu, Sep 8, 2016 at 10:05 AM, William Dunlap <wdun...@tibco.co

Re: [Rd] R (development) changes in arith, logic, relop with (0-extent) arrays

2016-09-08 Thread William Dunlap via R-devel
Shouldn't binary operators (arithmetic and logical) should throw an error when one operand is NULL (or other type that doesn't make sense)? This is a different case than a zero-length operand of a legitimate type. E.g., any(x < 0) should return FALSE if x is number-like and length(x)==0 but

Re: [Rd] withAutoprint({ .... }) ?

2016-09-02 Thread William Dunlap via R-devel
Re withAutoprint(), Splus's source() function could take a expression (literal or not) in place of a file name or text so it could support withAutoprint-like functionality in its GUI. E.g., > source(auto.print=TRUE, exprs.literal= { x <- 3:7 ; sum(x) ; y <- log(x) ; x - 100}, prompt="--> ") -->

Re: [Rd] A bug in the R Mersenne Twister (RNG) code?

2016-08-30 Thread William Dunlap via R-devel
Try comparing the streams for when the 625-integer versions of the seeds are identical. (R's seed is 626 integers: omit the first value, which indicates which random number generator the seed is for.). I find the the MKL Mersenne Twister results match R's (with occassional differences in the

[Rd] findInterval(all.inside=TRUE) for degenerate 'vec' arguments

2016-08-04 Thread William Dunlap via R-devel
What should findInterval(x,vec,all.inside=TRUE) return when length(vec)<=1, so there are no inside intervals? R-3.3.0 gives a decreasing map of x->output when length(vec)==1 and -1's when length(vec)==0. Would '0' in all those cases be better? > findInterval(x=c(10, 11, 12), vec=11,

<    1   2   3   4   5   6   >