Re: [Rd] suggestion: "." in [lsv]apply()

2020-04-16 Thread William Dunlap via R-devel
Passing in a function passes not only an argument list but also an environment from which to get free variables. Since your function doesn't pay attention to the environment you get things like the following. > wsapply(list(1,2:3), paste(., ":", deparse(s))) [[1]] [1] "1 : paste(., \":\", deparse

[Rd] edit() doubles backslashes when keep.source=TRUE

2020-05-14 Thread William Dunlap via R-devel
Is it just my installation or does edit() (or fix(), etc.) in R-4.0.0 double all the backslashes when options(keep.source=TRUE)? E.g., > options(keep.source=TRUE) > f <- function(x) { cat("\t", x, "\n", sep="") } > edit(f) # exit the editor without making any changes The editor (vi or notepad) sh

Re: [Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""

2020-05-15 Thread William Dunlap via R-devel
I agree: paste(collapse="something", ...) should always return a single character string, regardless of the value of recycle0. This would be similar to when there are no non-NULL arguments to paste; collapse="." gives a single empty string and collapse=NULL gives a zero long character vector. > pa

Re: [Rd] order function called on a data.frame?

2020-05-18 Thread William Dunlap via R-devel
do.call(order, df). -> do.call(order, unname(df)). While you are looking at order(), it would be nice if ';decreasing' could be a vector the the length of list(...) so you could ask to sort some columns in increasing order and some decreasing. I thought I put this on bugzilla eons ago, but perh

Re: [Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""

2020-05-21 Thread William Dunlap via R-devel
to be more logical / coherent / sensical .. > > Is the above all correct in your view? > > Assuming yes, I read basically two proposals, both agreeing > that recycle0 = TRUE should only ever apply to the action of 'sep' > but not the action of 'collapse'. &

Re: [Rd] paste(character(0), collapse="", recycle0=FALSE) should be ""

2020-05-22 Thread William Dunlap via R-devel
t;, "b"), NULL, c("c", "d"), sep = " ", collapse = ",", > > recycle0=TRUE) > > > > Currently that returns character(0), becuase the logic is > > essenttially (in pseudo-code) > > > > collapse(paste(c(&

[Rd] R-devel's ...names() questions

2020-05-22 Thread William Dunlap via R-devel
Am am missing something or does the new ...names() in R-devel not work right? > a <- function(x, ...) ...names() > a(a=stop("a"), b=stop("b")) [1] "a" "" > a(stop("x"), stop("unnamed"), c=stop("c"), d=stop("d")) [1] NA "" "" > version _ platform x86_64-pc-linux-gnu arch

[Rd] array() ignores illegal non-list dimnames

2015-12-17 Thread William Dunlap via R-devel
Is there a reason that array() silently ignores dimnames that are not a list but matrix() gives an error? > str(matrix(11:14, 2, 2, dimnames=c("Rows","Cols"))) Error in matrix(11:14, 2, 2, dimnames = c("Rows", "Cols")) : 'dimnames' must be a list > str(array(11:14, dim=c(2, 2), dimnames=

[Rd] as.data.frame and illegal row.names argument (bug in package:DoE.wrapper?)

2016-01-13 Thread William Dunlap via R-devel
as.data.frame methods behave inconsistently when they are given a row.name argument of the wrong length. The matrix method silently ignores row.names if it has the wrong length and the numeric, integer, and character methods do not bother to check and thus make an illegal data.frame. > as.data.fr

[Rd] smooth()'s output attribute 'endrule'?

2016-02-05 Thread William Dunlap via R-devel
What is the point of the 'endrule' attribute of smooth()'s return value? For the simpler smooths (not involving 'S'?) it is value of the endrule argument, for more complicated smooths it is the endrule not asked for (the choices are 'Tukey' and 'copy'). For kind="S", it is not in the return value

[Rd] keepNA in nchar and nzchar

2016-03-19 Thread William Dunlap via R-devel
Is it intended that in yesterday's version of R-devel the default value of keepNA is different in nchar (NA) and nzchar (FALSE)? > args(nchar) function (x, type = "chars", allowNA = FALSE, keepNA = NA) NULL > args(nzchar) function (x, keepNA = FALSE) NULL Is it intended that for keepN

Re: [Rd] Optimization bug when byte compiling with gcc 5.3.0 on windows

2016-04-04 Thread William Dunlap via R-devel
>If I recall correctly, some eigen vectors had their >direction flipped (negative values became positive and vice versa). >Did you notice anything of this kind when running 'make check' and >'make check recommended' ? It is important to us that numeric results >are reproducible between versions of

Re: [Rd] (no) circular dependency

2016-04-07 Thread William Dunlap via R-devel
> but this strategy quickly inflates the number of packages on CRAN. CRAN contains 8210 packages today, so I would not worry about adding an extra one. Also, I think several small packages are preferable to one large one because attaching a big one just to get the one or two functions you want is

[Rd] locked environments

2016-04-20 Thread William Dunlap via R-devel
Shouldn't the following 4 ways to alter an object in a locked environment either all work or all fail? (All working would be nice, I think.) E <- new.env() assign("var", c(1,2,3,4), envir=E) lockEnvironment(E, bindings=FALSE) E$var[1] <- 101 ; E$var #[1] 101 2 3 local(var[2]

Re: [Rd] "cophenetic" function for objects of class "dendrogram"

2016-04-21 Thread William Dunlap via R-devel
I think the results differ only in the order of the labels. The following function puts the labels in a standard order and then the results are the same: canonicalize.dist <- function (distObject) { o <- order(labels(distObject)) as.matrix(distObject)[o, o, drop = FALSE] } ide

Re: [Rd] "cophenetic" function for objects of class "dendrogram"

2016-04-21 Thread William Dunlap via R-devel
wdunlap tibco.com On Thu, Apr 21, 2016 at 7:59 AM, William Dunlap wrote: > I think the results differ only in the order of the labels. The following > function > puts the labels in a standard order and then the results are the same: > > canonicalize.dist <- function (distObjec

Re: [Rd] Single-threaded aspect

2016-05-12 Thread William Dunlap via R-devel
The R language itself has features that limit how much mulitthreading/parallel processing can be done. There are functions with side effects, such as library(), plot(), runif(), <-, and <<- and there are no mechanisms to isolate them. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, May 12,

[Rd] meaning of 'Depends: R (> 3.0.2)'

2016-05-16 Thread William Dunlap via R-devel
In knitr-1.13 the DESCRIPTION file's Depends line uses a ">" instead of the usual ">=". Depends: R (> 3.0.2) I don't see the strict greater than in Writing R Extensions. Does it really mean that 3.0.2 is not suitable and that whatever version comes after it is? Bill Dunlap TIBCO Software wdunla

Re: [Rd] Suggestion: mkString(NULL) should be NA

2016-05-24 Thread William Dunlap via R-devel
Why should Rf_mkString(NULL) produce NA_STRING instead of "" (R_BlankString)? I prefer that passing in a nil pointer would cause an error instead, as the nil may arise by accident, perhaps a pointer to freed memory, and I would like to be notified that my code is bad instead of getting a random NA

[Rd] odd warning unlinking symlink on Windows

2016-05-25 Thread William Dunlap via R-devel
While constructing some tests of symbolic link code in R, I got an odd warning when trying the remove a symbolic link: file.create(tfile <- tempfile()) #[1] TRUE file.symlink(tfile, tlink <- tempfile()) #[1] TRUE unlink(tlink) #Warning message: #In unlink(tlink) : # cannot delete reparse point 'C

Re: [Rd] Detecting user interrupts in R_tryEval

2016-07-07 Thread William Dunlap via R-devel
In R code tryCatch can detect the difference. Hit control-C (on Unixen) or Escape (on Windows) to interrupt the long-running for loop and see that the interrupt clause gets called: > z <- tryCatch(for(i in seq_len(1e8))log(exp(i/10)), error=function(e)e, interrupt=function(e)e) ^C> dput(z) struct

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread William Dunlap via R-devel
One way around this problem is to make a new environment whose parent environment is .GlobalEnv and which contains only what the the call to lm() requires and to compute lm() in that environment. E.g., tfun1 <- function (subset) { junk <- 1:1e+06 env <- new.env(parent = globalenv())

Re: [Rd] Model object, when generated in a function, saves entire environment when saved

2016-07-27 Thread William Dunlap via R-devel
=subset, lm(Sepal.Length ~ Sepal.Width, data=iris, subset=subset)$coef) } saveSize(tfun2(1:4)) #[1] 152 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jul 27, 2016 at 11:19 AM, William Dunlap wrote: > One way around this problem is to make a new environment whose > parent environment is .Gl

[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, all.inside=T

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 last

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="--> ") --> x

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] 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 wrote: > > > On Thu, Sep 8, 2016 at 10:05 AM, William Dunlap wrote: > >> Shouldn't

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 Not

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

2016-09-09 Thread William Dunlap via R-devel
gt; 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 wrote: > > It should be the case that tan(pi*x) != tanpi(x) in many cases - that is > why > > it was added. The limits fro

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

2016-09-09 Thread William Dunlap via R-devel
; > 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:44 PM, Willi

Re: [Rd] R-intro: function 'stderr' and 'sd'

2016-09-13 Thread William Dunlap via R-devel
While you are editing that, you might change its name from 'stderr' to standardError (or standard_error, etc.) so as not to conflict with base::stderr(). Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Sep 13, 2016 at 8:55 AM, Martin Maechler wrote: > > Suharto Anggono Suharto Anggono

[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) > str(strcapture("([[:alpha

[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("(.+) (.+)"

Re: [Rd] error handling in strcapture

2016-09-21 Thread William Dunlap via R-devel
M, Michael Lawrence 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, William Dunlap via R-devel &g

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 function

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 requ

Re: [Rd] error handling in strcapture

2016-10-04 Thread William Dunlap via R-devel
s 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 wrote: > > If there ar

Re: [Rd] error handling in strcapture

2016-10-04 Thread William Dunlap via R-devel
col = ntokens, byrow = TRUE) : data length [20] is not a sub-multiple or multiple of the number of rows [7] > strcapture("(.)(.)(.)", c("abc", "def"), proto=list(A="")) A 1 a 2 c 3 d 4 f Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Oct 4, 20

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 the correct list for my questi

Re: [Rd] anonymous function parsing bug?

2016-10-21 Thread William Dunlap via R-devel
n error ("attempt to apply non-function") and > ## > f2<-function(x) { return(2*x) }(2) > f2(3) > ## > is perfectly fine. Thus the return statement changes the interpretation as > a function? Or do I miss something? > > Best wishes > Wilm > > > Am 21.10.201

Re: [Rd] anonymous function parsing bug?

2016-10-21 Thread William Dunlap via R-devel
Am 21.10.2016 um 18:10 schrieb William Dunlap: > > Are you saying that f1 <- function(x) log(x) f2 <- function(x) { log } (x) should act differently? yes. But that would mean that {log} would act differently than log. I suppose it is a matter of taste, but I say yuck. As

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 error:

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 't

[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: [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 R. AFAIK R does only han

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 tibco.co

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 >> on Wed, 25 Jan 2017 16:31:

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]), strin

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] Pressing either Ctrl-\ of Ctrl-4 core dumps R

2017-02-10 Thread William Dunlap via R-devel
Control-backslash is the default way to generate SIGQUIT from the keyboard on Unix and SIGQUIT, by default, aborts the process and causes it to produce a core dump. Do you want R to catch SIGQUIT? % stty --all speed 38400 baud; rows 24; columns 64; line = 0; intr = ^C; quit = ^\; erase = ^H; kill

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 a

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 fun

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 the problem mentioned below. I

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

[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. > str(dimnam

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. Bill

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
>> I think SPECIALS are already have the proper precedence for both unary >> 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

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
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
thout >> > fully >> > doing so. See the roxygen comments in Hadley and Lionel's rlang package >> > here: https://github.com/hadley/rlang/blob/master/R/tidy-unquote.R >> > >> > The desired precedence of such a unary operator is not clear to me. The >> > way >>

Re: [Rd] Support for user defined unary functions

2017-03-17 Thread William Dunlap via R-devel
tors (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%` <- function(x) tail(x, n = 1) >>> %l% 1:5 >>&

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 In

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 in

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. T

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 the issue of a child proces

[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] 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 t

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

2017-04-26 Thread William Dunlap via R-devel
hink I set mine to three days, and I can';t recall ever having a > problem that was more than a minor annoyance (help breaking) on old R > processes. > > Cheers, > > Brian > > -- > Brian G. Peterson > http://braverock.com/brian/ > Ph: 773-459-4973 > IM: bgpbrav

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

2017-05-09 Thread William Dunlap via R-devel
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 use as a label on a plot. It is often followed by returnValue$call[[1]] <- quote(myName) E.g., I see it in packages "latticeExtra" and "

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
:36 AM, William Dunlap via R-devel > 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 use as a label on a > > plot. It is often foll

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 > y

Re: [Rd] Philosophy behind converting Fortran to C for use in R

2017-06-06 Thread William Dunlap via R-devel
Here are three reasons for converting Fortran code, especially older Fortran code, to C: 1. The C-Fortran interface is not standardized. Various Fortran compilers pass logical and character arguments in various ways. Various Fortran compilers mangle function and common block names in variousl wa

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] 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 no

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 heard from our instru

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

2017-06-16 Thread William Dunlap via R-devel
dunlap tibco.com On Fri, Jun 16, 2017 at 11:53 AM, peter dalgaard 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 20:20 , William Dun

[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 er

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 = .Glo

[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] 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' 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))) >

Re: [Rd] force promises inside lapply

2017-07-31 Thread William Dunlap via R-devel
[[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})))() >[1] TRUE > > >

[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 = FALS

[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() ) cat(fi

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 wrote: > >>>>> William Dunlap via R-devel > >>&g

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] 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 to

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 unifor

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 use a diffe

[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 of

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

2017-11-08 Thread William Dunlap via R-devel
eck = TRUE the default though. > > /Henrik > > On Wed, Nov 8, 2017 at 4:43 PM, William Dunlap via R-devel > wrote: > > 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 >

[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 funct

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

2017-12-01 Thread William Dunlap via R-devel
("string") #[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]

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 expr

[Rd] mget(missingArgument)?

2020-06-22 Thread William Dunlap via R-devel
Currently, when mget() is used to get the value of a function's argument with no default value and no value in the call it returns the empty name (R_MissingArg). Is that the right thing to do or should it return 'ifnotfound' or give an error? E.g., > a <- (function(x) { y <- "y from function's en

[Rd] Change in lapply's missing argument passing

2020-06-26 Thread William Dunlap via R-devel
Consider the following expression, in which we pass 'i=', with no value given for the 'i' argument, to lapply. lapply("x", function(i, j) c(i=missing(i),j=missing(j), i=) >From R-2.14.0 (2011-10-31) through R-3.4.4 (2018-03-15) this evaluated to c(i=TRUE, j=FALSE). From R-3.5.0 (2018-04-23) th

[Rd] CAR0 vs. EXTPTR_PTR

2020-07-22 Thread William Dunlap via R-devel
I know that binary packages are R-version specific, but it was a bit surprising that Rcpp 1.0.5 built with R-4.0.2 cannot be loaded into R-4.0.0. % R-4.0.0 --quiet > library(Rcpp, lib="lib-4.0.2") Error: package or namespace load failed for ‘Rcpp’ in dyn.load(file, DLLpath = DLLpath, ...): unable

Re: [Rd] lm() takes weights from formula environment

2020-08-10 Thread William Dunlap via R-devel
I assume you are concerned about this because the formula is defined in one environment and the model fitting with weights occurs in a separate function. If that is the case then the model fitting function can create a new environment, a child of the formula's environment, add the weights variable

Re: [Rd] NAs and rle

2020-08-26 Thread William Dunlap via R-devel
Splus's rle() also grouped NA's (separately from NaN's): % Splus TIBCO Software Inc. Confidential Information Copyright (c) 1988-2008 TIBCO Software Inc. ALL RIGHTS RESERVED. TIBCO Spotfire S+ Version 8.1.1 for Linux 2.6.9-34.EL, 32-bit : 2008 > dput(rle(c(11,11,NA,NA,NA,NaN,14,14,14,14))) list("l

<    1   2   3   4   5