Re: [Rd] Historical NA question

2014-05-06 Thread William Dunlap
You can also use is.element(els,set) instead of the equivalent els%in%set and leave your precedence problems behind. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, May 5, 2014 at 10:35 PM, peter dalgaard wrote: > > On 06 May 2014, at 01:05 , Hervé Pagès wrote: > >> >> BTW, that %in% has p

Re: [Rd] Historical NA question

2014-05-06 Thread William Dunlap
Here is source code for help(Syntax) from S+, which I think follows closely the original S help file: .Ix precedence The following \f6infix\fP operators are recognized by the parser. They are listed in decreasing precedence. In the event of ties, evaluation is from left to right. .sp .in +.5i .nf .

Re: [Rd] Historical NA question

2014-05-06 Thread William Dunlap
08:54 AM, William Dunlap wrote: >> >> You can also use is.element(els,set) instead of the equivalent >> els%in%set > > > No they are not *equivalent*. Equivalent means you could substitute > one by the other in your code without changing its behavior. > > H.

Re: [Rd] Historical NA question

2014-05-06 Thread William Dunlap
/06/2014 12:36 PM, William Dunlap wrote: >> >> When does els%in%set give a different result than is.element(els,set)? >> I assumed they were copied form S+, where they are the same except >> for argument names, but I may be wrong. > > > > els <- 2:1 >

Re: [Rd] Historical NA question

2014-05-06 Thread William Dunlap
errors with %in%. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, May 6, 2014 at 1:28 PM, Hervé Pagès wrote: > On 05/06/2014 01:15 PM, William Dunlap wrote: >> >> In your example els%in%set gave the same result as >> is.element(els,set), but because of precedence issues

Re: [Rd] historical significance of Pr(>Chisq) < 2.2e-16

2014-05-07 Thread William Dunlap
It may come a time before the pchisq() function had the lower.tail argument. In those days you had the compute the upper tail as 1-pchisq(x2, df). For any eps<2.2e-16 (.Machine$double.eps), 1-eps==1 so 1-(1-eps)==0 so you would get, e.g., > 1-pchisq(100,2) [1] 0 and people would say 'but the

Re: [Rd] Inconsistency in vector printing depending on length

2014-05-16 Thread William Dunlap
> It seems that when a vector has 10 elements, it prints out differently than > one with 9 (extra space before the opening bracket). I can't see why this > is happening. It is happening because the print routine wants to be ready to print all the line-beginning [index] tags aligned with each other

Re: [Rd] Question on Code snippet semantics

2014-07-21 Thread William Dunlap
subsitute(expr), with only one argument, is only useful inside of a function and then only when the expression, expr, involves an argument to the function. Then the unevaluated actual arguments to the function are substituted into the [unevaluated] expression. E.g., f <- function(x, y=stop("y

Re: [Rd] portableParalleSeeds Package violation, CRAN exception?

2014-08-06 Thread William Dunlap
You can make an environment called streamsEnv in your package by adding streamsEnv <- new.env() to one of your R/*.R files. (its parent environment will be namespace:yourPackage) and your functions can assign things to this environment instead of to .GlobalEnv. Bill Dunlap TIBCO Software wdunla

Re: [Rd] RFC: diag(x, n) not preserving integer and logical x

2014-08-11 Thread William Dunlap
Would you allow a list argument to diag() as well? I see that Matrix::Diagonal does not accept it. Perhaps nothing in Matrix deals with matrices of lists, but they are handy and for diag() it may be simpler to allow lists than to check for and reject them. Bill Dunlap TIBCO Software wdunlap tibco

Re: [Rd] parallel::detectCores(TRUE) gives: Error in system(cmd, TRUE) : error in running command

2014-08-22 Thread William Dunlap
The same is true in R-2.14.1 on Ubuntu 12.04.4 LTS . Put a trace on system with trace(system, quote(print(command))) parallel::detectCores(TRUE) and you will see the offending shell command. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Aug 22, 2014 at 1:03 PM, Marius Hofert wrote:

Re: [Rd] parallel::detectCores(TRUE) gives: Error in system(cmd, TRUE) : error in running command

2014-08-22 Thread William Dunlap
uot;system" in package "base" > [1] "system" >> > Tracing system(cmd, TRUE) on entry > [1] "/usr/sbin/sysctl -n hw.ncpu 2>/dev/null" > Error in system(cmd, TRUE) : error in running command >> > > On Fri, Aug 22, 2014 at 6:13 PM,

Re: [Rd] Intel Fortran compiler returns a -1 TRUE value

2014-09-30 Thread William Dunlap
In S+ and S it was valid to pass logicals to .Fortran, where they got mapped into the appropriate bit pattern. (The trouble was that 'appropriate' was compiled into the program - so you were locked into our compiler vendor's choice). Passing them between Fortran code and C code has always been a

Re: [Rd] [R logs] Help in develop a simply logs package

2014-10-07 Thread William Dunlap
R has support for options(warning.expression=...), but it acts differently than the options(error=...). S (and S+) let the user override the default '.Program' expression. Its default value was essentially print(.Last.value <- eval(parse(file=stdin( but a replacement could add stuff like pr

Re: [Rd] Most efficient way to check the length of a variable mentioned in a formula.

2014-10-17 Thread William Dunlap
I would use eval(), but I think that most formula-using functions do it more like the following. getRHSLength <- function (formula, data = parent.frame()) { rhsExpr <- formula[[length(formula)]] rhsValue <- eval(rhsExpr, envir = data, enclos = environment(formula)) length(rhsValue) }

Re: [Rd] Most efficient way to check the length of a variable mentioned in a formula.

2014-10-17 Thread William Dunlap
length(rhsValue) } so that the function firstHalf is found in the following > X <- 1:10 > getRHSLength((function(){firstHalf<-function(x)x[seq_len(floor(length(x)/2))]; ~firstHalf(X)})()) [1] 5 Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 17, 2014 a

Re: [Rd] Most efficient way to check the length of a variable mentioned in a formula.

2014-10-17 Thread William Dunlap
>> y <- 10:1 >> z <- 11:20 >> afun(z ~ fun(x) + y) > [[1]] > [1] 11 12 13 14 15 16 17 18 19 20 > > [[2]] > [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 > > [[3]] > [1] 10 9 8 7 6 5 4 3 2 1 > > It might be I'm walkin

Re: [Rd] Options that are local to the package that sets them

2014-10-31 Thread William Dunlap
You can put the following 3 objects, an environment and 2 functions that access it, in any package that need some package-specific storage (say your pkgB1 and pkgB2). .pkgLocalStorage <- new.env(parent = emptyenv()) assignInPkgLocalStorage <- function(name, object) { .pkgLocalStorage[[

Re: [Rd] ambiguity in the documented return value of Null() from package MASS

2014-11-10 Thread William Dunlap
> Presumably, the help file wording goes back to S-PLUS which > (to my recollection) didn't allow zero-extent matrices. Splus (and S) started having reasonable support for zero-extent matrices in May 2001 (i.e., Splus 6.0, which I think corresponds to S version 4-m of June 2, 1999), Splus5.0 (Nov

Re: [Rd] Problem with build and check

2014-11-12 Thread William Dunlap
'Writing R Extensions', section 2.1 Rd format, says" Comments run from a percent symbol % to the end of the line in all types of text (as on the first line of the load example). Because backslashes, braces and percent symbols have special meaning, to enter them into text sometimes requires escape

Re: [Rd] setequal: better readability, reduced memory footprint, and minor speedup

2015-01-08 Thread William Dunlap
> why is there no setcontains()? Several packages define is.subset(), which I am assuming is what you are proposing, but it its arguments reversed. E.g., package:algstat has is.subset <- function(x, y) all(x %in% y) containsQ <- function(y, x) all(x %in% y) and package:rje has essentially t

[Rd] as.hexmode(big number) fails in R-3.1.2

2015-01-09 Thread William Dunlap
There was recently a discussion here on how to tell if a number was integral. Did that prod someone into change as.hexmode in R-3.1.2 so that it aborts if given a number to big to fit into a 32-bit integer? It returned NA, with two warnings in R-3.1.1. % R-3.1.2 --quiet --vanilla > as.hexmode(c(1

Re: [Rd] :: and ::: as .Primitives?

2015-01-22 Thread William Dunlap
> if I want to use foo::bar many times, say > in a loop, I would do > > foo_bar <- foo::bar > > and use foo_bar, or something along those lines. The foreach package does that with a function from the compiler package, so that foreach can work on old version of R: comp <- if (getRversion() < "2.1

Re: [Rd] [Q] Get formal arguments of my implemented S4 method

2015-01-29 Thread William Dunlap
I wish it didn't have to depend on the name '.local'. Back when I wrote a lot of S4 methods I avoided the auto-generated .local and named the local function something that made sense so that is was easier for a user to track down the source of an error. E.g., define the generic QQQ with numeric a

Re: [Rd] error code 1 from Lapack routine 'dsyevr'

2015-02-02 Thread William Dunlap
You can start diagnosing the problem by capturing the matrix that caused eigen() to stop. You can do this in a variety of ways; here is one trace(eigen, quote(lastEigenX <<- x)) After setting the trace, make your offending function call and after the error the global variable 'lastEigenX' wil

Re: [Rd] iterated lapply

2015-02-26 Thread William Dunlap
Would introducing the new frame, with the call to local(), cause problems when you use frame counting instead of <<- to modify variables outside the scope of lapply's FUN, I think the frame counts may have to change. E.g., here is code from actuar::simul() that might be affected: x <- unl

Re: [Rd] nonlinear least square

2015-03-04 Thread William Dunlap
Look at the 'self-starting' functions for nls(), such as SSasymp(). Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 4, 2015 at 5:01 AM, Evans Otieno Ochiaga < evansochi...@aims.ac.za> wrote: > Hi to all, > > Is there a way we can fit a non linear model to a data using non linear > least

Re: [Rd] Help

2015-03-18 Thread William Dunlap
You can use nls's 'control' argument to work around this problem. Read help(nls.control) for details. nls(control = nls.control(minFactor=2^-20), ...) will allow a smaller step factor than the default 2^-10 and loosening the convergence tolerance with nls(control = nls.control(tol=1e-4)) may

Re: [Rd] F77_CALL/NAME problem

2015-03-25 Thread William Dunlap
You said you changed F77_NAME(DGESV) to dgesv_ to make it work and inferred that F77_NAME was the the problem. I suspect that things got better because you changed the capitalization and that F77_NAME(dgesv) would have worked as well. Adding #include to your code would declare these things as

Re: [Rd] Segfault with match()

2015-03-30 Thread William Dunlap
Did you leave out the warning from "+", which should be an error, as it produces an illegal ordered factor in this case and factor+factor is nonsensical? Or is the warning missing in the current development version of R? > x <- factor("A", ordered=FALSE) + factor(c("B","C"), ordered=TRUE) Warning

Re: [Rd] Segfault with match()

2015-03-30 Thread William Dunlap
For consistency with factor+factor and factor+numeric, factor+ordered should produce a logical vector filled with NAs, not throw an error. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Mar 30, 2015 at 1:50 PM, William Dunlap wrote: > Did you leave out the warning from "+",

Re: [Rd] Redefining {

2015-04-17 Thread William Dunlap
One could redefine the "{" function with something like `{` <- function(...) simplify2array(list(...)) but then you would have to live with the syntax it requires (semicolons for separators instead of commas) > {1; 2; 3} [1] 1 2 3 > {{11;12;13}; {21;22;23}; {31;32;33}} [,1] [,2

Re: [Rd] Redefining {

2015-04-17 Thread William Dunlap
e_scalar$`{` function (x) { build_sql("(", x, ")") } Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Apr 17, 2015 at 7:49 AM, William Dunlap wrote: > One could redefine the "{" function with something like > `{` <- function(...)

Re: [Rd] model frames and update()

2015-04-23 Thread William Dunlap
> "Save the model frame in case you need to refit something next month" > does not appear to be a safe approach to reproducible research. Is this a standard recommendation? It will not work in many cases. E.g., if you use lm() to model the sum of some variables the model.frame contains only the

Re: [Rd] R CMD check and missing imports from base packages

2015-04-29 Thread William Dunlap
> And in general a developer would avoid masking a function > in a base package, so as not to require the user to distinguish > between stats::density() and igraph::density(). Maybe the > example is not meant literally. The 'filter' function in the popular 'dplyr' package masks the one that has be

Re: [Rd] Reading exit code of pipe()

2015-05-14 Thread William Dunlap
The difference in the return value of close(pipeConnectionObject) seems to depend on whether the pipe connection was opened via the pipe() or open() functions (close() returns NULL) > con <- pipe("ls") > open(con, "r") > readLines(con, n=1) [1] "1032.R" > print(close(con)) NULL

Re: [Rd] "What Calls What" diagram. Flow Chart?

2011-10-10 Thread William Dunlap
Have you tried using trace()? E.g., > library(lavaan) > trace(lavaan) > HS.model <- ' visual =~ x1 + x2 + x3 +textual =~ x4 + x5 + x6 +speed =~ x7 + x8 + x9 ' > > fit <- cfa(HS.model, data=HolzingerSwineford1939) trace: lavaan(

Re: [Rd] trace an Rd conversion error in R cmd check

2011-10-12 Thread William Dunlap
Good luck in tracking down the problem. I won't give any help there. I've seen this sort of error message (or worse) when using system.file() and the desired file didn't exist. If that is the problem, add the newish argument mustWork=TRUE to the call to system.file so you get an error message fr

Re: [Rd] One step way to create data frame with variable "variable names"?

2011-11-11 Thread William Dunlap
> plotx <- "someName" > modx <- "otherName" > data.frame( structure(list(c(1, 2, 3, 4)), names=plotx), structure(list(c(4, > 4, 4, 4)), names=modx)) someName otherName 11 4 22 4 33 4 44 4 (I think this is more of an R-help question

Re: [Rd] R CMD ?

2011-11-28 Thread William Dunlap
The shell command R CMD something currently acts as though it puts R_HOME/bin on the front of PATH, looks for an executable file called 'something' in PATH, and then executes it. The executable may call R or it may not. I think that running an R script file is sufficiently different from runnin

Re: [Rd] delete.response leaves response in attribute dataClasses

2012-01-05 Thread William Dunlap
I had noticed the same thing but figured that most people (writers of predict methods) would be looking up entries in dataClasses by name and not by position, since predict's newdata argument need not have entries in the same order as the data used to fit the model. Hence the extra entry would not

Re: [Rd] delete.response leaves response in attribute dataClasses

2012-01-05 Thread William Dunlap
BCO Software wdunlap tibco.com > -Original Message- > From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-project.org] On > Behalf Of William Dunlap > Sent: Thursday, January 05, 2012 12:57 PM > To: Paul Johnson; R Devel List > Subject: Re: [Rd] delete.response

Re: [Rd] delete.response leaves response in attribute dataClasses

2012-01-06 Thread William Dunlap
> -Original Message- > From: Paul Johnson [mailto:pauljoh...@gmail.com] > Sent: Friday, January 06, 2012 11:17 AM > To: William Dunlap > Cc: R Devel List > Subject: Re: [Rd] delete.response leaves response in attribute dataClasses > > Thanks, Bill > > Counte

[Rd] inconsistent overflow handling by strtoi() on 32-bit Windows

2012-01-10 Thread William Dunlap
Using the precompiled R 2.14.1 on 32-bit Windows XP strtoi(x) gives 2^31-1 for x>2^31-1 but NA when x goes out of range in the negative direction: > x <- c("2147483646", "2147483647", "2147483648", "2147483649") > str(strtoi(x)) int [1:4] 2147483646 2147483647 2147483647 2147483647 > str(strtoi(s

Re: [Rd] factor S4 class is NA when as.character method exists

2012-01-24 Thread William Dunlap
Here is code that does make factor() work on a new class like yours. It uses Sv3 methods. > setClass("foo", contains="numeric") [1] "foo" > as.character.foo <- function(x) paste("x=",x@.Data,sep="") > unique.foo <- function(x, ...) structure(NextMethod("unique"), class=class(x)) > someF

Re: [Rd] ftable.formula

2012-01-26 Thread William Dunlap
Put the formula first in the argument list or label the data argument data= and put the formula after it if you want to use the formula method for ftable. > ftable(data=UCBAdmissions, Gender + Admit ~ Dept) Gender MaleFemale Admit Admitted Rejected Admitted Rejecte

Re: [Rd] misfeature: forced file.copy() of a file over itself truncates the file ...

2012-01-27 Thread William Dunlap
Since the problem can only occur if the 'to' file exists, a check like if (normalizePath(from) == normalizePath(to)) { stop("'from' and 'to' files are the same") } (after verifying that 'to', and 'from', exist) would avoid the problem. S+ has a function, match.path, that can say if two

[Rd] inconsistency with names on call object

2012-02-02 Thread William Dunlap
With most sorts of objects the following three expression have the same value: names(obj) attr(obj, "names") attributes(obj)$names However, for call objects the last gives NULL, whether there are names or not. > obj <- quote(func(one=1)) > obj func(one = 1) > names(obj)

Re: [Rd] Canonical package directory name for JAR files?

2012-02-08 Thread William Dunlap
For what it is worth, the S+ package system uses the java directory in source packages to store java source code (under pkg/java/src/, using the usual directory structure that follows the class structure under there), prebuilt jar files (in pkg/java/prebuiltjars, no subdirectories), and a Makevars

Re: [Rd] Canonical package directory name for JAR files?

2012-02-08 Thread William Dunlap
nesday, February 08, 2012 1:46 PM > To: William Dunlap > Cc: Roebuck,Paul L; R-Devel > Subject: Re: [Rd] Canonical package directory name for JAR files? > > Unfortunately we cannot mandate JDK so packages have to use the build stage > for compilation so the S+ > model doesn&#x

Re: [Rd] R CMD SHLIB in Windows XP - No output at all

2012-02-15 Thread William Dunlap
Does the following example help? I installed Duncan Murdoch's Rtools-2.13 into E:\Rtools-2.13 and R into E:\Program Files\R\R-2.14.1. I put a small file of C code into E:\temp\junk.c. Here is record of what I did after opening a new cmd.exe window. Setting PATH is critical: put the 2 bin directo

Re: [Rd] R CMD SHLIB in Windows XP - No output at all

2012-02-15 Thread William Dunlap
It looks like my original path had R_HOME for 2.14.0 in it, but what I did works when that was changed. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-project.org] On > Behalf Of Willi

Re: [Rd] executable files R package

2012-02-17 Thread William Dunlap
If you put your prebuilt.exe into a directory under the 'source' package's inst directory, say yourPkg/inst/executables/win32, then the installed package will have them in in yourPkg/executables/win32 and the user (via code you write, presumably) can get the full path to the executable in the insta

Re: [Rd] Julia

2012-03-05 Thread William Dunlap
I haven't used Julia yet, but from my quick reading of the docs it looks like arguments to functions are passed by reference and not by value, so functions can change their arguments. My recollection from when I first started using S (in the course of a job helping profs and grad students do stati

Re: [Rd] Julia

2012-03-05 Thread William Dunlap
rom: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-project.org] On > Behalf Of Hervé Pagès > Sent: Monday, March 05, 2012 3:59 PM > To: oliver > Cc: R-devel > Subject: Re: [Rd] Julia > > Hi Oliver, > > On 03/05/2012 09:08 AM, oliver wrote: > > On Mon, Mar

Re: [Rd] Julia

2012-03-06 Thread William Dunlap
; -Original Message- > From: oliver [mailto:oli...@first.in-berlin.de] > Sent: Tuesday, March 06, 2012 1:12 AM > To: William Dunlap > Cc: Hervé Pagès; R-devel > Subject: Re: [Rd] Julia > > On Tue, Mar 06, 2012 at 12:35:32AM +, William Dunlap wrote: > [...] >

Re: [Rd] Julia

2012-03-07 Thread William Dunlap
do that. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: oliver [mailto:oli...@first.in-berlin.de] > Sent: Wednesday, March 07, 2012 10:22 AM > To: Dominick Samperi > Cc: William Dunlap; R-devel > Subject: Re: [Rd] Julia > > On

Re: [Rd] Julia

2012-03-08 Thread William Dunlap
functions (hence packages) difficult. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: oliver [mailto:oli...@first.in-berlin.de] > Sent: Thursday, March 08, 2012 7:40 AM > To: William Dunlap > Cc: R-devel > Subject: Re: [Rd] Julia >

Re: [Rd] Julia

2012-03-08 Thread William Dunlap
of easily reusable functions that S allows. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: oliver [mailto:oli...@first.in-berlin.de] > Sent: Thursday, March 08, 2012 2:23 PM > To: William Dunlap > Cc: R-devel > Subject: Re: [Rd] Julia

Re: [Rd] Why is there no within.environment function?

2012-03-21 Thread William Dunlap
Wouldn't within.environment be identical to with.environment? > e <- new.env() > with(e, { One <- 1 ; Two <- 2+2i ; Theee <- One + Two }) > objects(e) [1] "One" "Theee" "Two" It might make the transition between lists and environments simpler if within.environment existed. Bill Dunlap S

Re: [Rd] CRAN policies

2012-03-29 Thread William Dunlap
> -Original Message- > From: r-devel-boun...@r-project.org [mailto:r-devel-boun...@r-project.org] On > Behalf > Of Terry Therneau > Sent: Thursday, March 29, 2012 7:02 AM > To: r-devel@r-project.org > Subject: Re: [Rd] CRAN policies > > On 03/29/2012 05:00 AM, r-devel-requ...@r-project.or

Re: [Rd] CRAN policies

2012-03-29 Thread William Dunlap
ubject: Re: [Rd] CRAN policies > > William Dunlap tibco.com> writes: > > > > -Original Message- > > > The survival package has a similar special case: the routines for > > > expected population survival are set up to accept multiple types of date >

Re: [Rd] CRAN policies

2012-03-29 Thread William Dunlap
ot;local" "poisson" "quasi" [28] "quasibinomial" "quasipoisson" "quote" [31] "Quote" "require" "substitute" [34] "with" Bill Dunlap Spotfire,

Re: [Rd] CRAN policies

2012-03-30 Thread William Dunlap
0 > people who have written CRAN packages by now; every extra check and non-back- > compatible additional requirement runs the risk of generating false-negatives > and > incurring many extra person-hours to "fix" non-problems. Plus someone needs to > document and explain the che

Re: [Rd] I wish xlim=c(0, NA) would work. How about I send you a patch?

2012-04-16 Thread William Dunlap
plot(1:10, xlim=c(10,1)) reverses the x axis. If we allow plot(1:10, xlim=c(5,NA)), which direction should it go?Would this require new parameters, {x,y}{min,max} or new paremeters {x,y}{axisDirection}? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > Fro

Re: [Rd] Column(row)wise minimum and maximum

2012-04-19 Thread William Dunlap
S+ has such functions with a slightly different naming convention: it puts an 's' after each function. E.g., colMaxs instead of your colMax. "colMaxs" "colMeans" "colMedians" "colMins" "colProds" "colQuantiles" "colRanges""colStdevs""colSums" "colVars" "ro

Re: [Rd] Version of substitute that evaluates it's first argument

2012-07-27 Thread William Dunlap
For what it's worth, S+'s substitute() has had an evaluate=FALSE argument to substitute() for quite a while (I think it came with Sv4). evaluate=TRUE means to evaluate its first arument: > myCall <- call("myFunc", as.name("arg1")) > substitute(myCall, list(arg1=as.name("newArg1")), evaluate=TR

Re: [Rd] Rd] Numerics behind splineDesign

2012-08-02 Thread William Dunlap
If R's bs() and ns() are like S+'s (they do give very similar results* and S+'s were written by Doug Bates), then bs() does not do any linear algebra (like qr()) on splineDesign's output. bs() needs to come up with a default set of knots (if the user didn't supply them), combine the Boundary.knots

Re: [Rd] Quiz: How to get a "named column" from a data frame

2012-08-18 Thread William Dunlap
That would have been essentially my suggestion as well. I prefer its clarity (and speed). I didn't know if you wanted your solution to also apply to matrices embedded in data.frames. In S+ rownames<-() works on vectors (because it calls the generic rowId<-()) so the following works: > f4 <- fu

[Rd] as.data.frame.character lacks nm= argument

2012-09-13 Thread William Dunlap
Is the following behavior with as.data.frame(nm=...) a bug? It is an inconsistency: > as.data.frame(LETTERS[1:10], nm="FirstTenLetters") Error in as.data.frame.vector(x, ..., nm = nm) : formal argument "nm" matched by multiple actual arguments nm= works for integer arguments: > as.data.fram

Re: [Rd] as.data.frame.character lacks nm= argument

2012-09-14 Thread William Dunlap
q_len(100)), nm="x")) user system elapsed 0.170.000.17 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] > Sent: Friday, September 14, 2012 6:25 AM > To: Bert

Re: [Rd] Risk of readRDS() not detecting race conditions with parallel saveRDS()?

2012-09-15 Thread William Dunlap
Why not write the RDS file more atomically - write it to a temporary file and rename that file to its final name when it is completely written? E.g., saveRDS.atomically function (object, file, ...) { tfile <- tempfile(basename(file), dirname(file)) on.exit(if (file.exists(tfile)) unlink(

[Rd] should delete.response(response~predictor) return ~predictor?

2012-09-21 Thread William Dunlap
Thomas, I noticed the delete.response() just returns its input if the input is not of class "terms". Hence we get surprising (to me) results like > env <- new.env() > env # formulae have an environment, calls do not > with(env, delete.response(y ~ x1 + x2)) # class "formula" y ~ x1 +

Re: [Rd] error on uneven recycling?

2012-09-24 Thread William Dunlap
That is an error in Splus 8.3. It must have changed quite a while ago - it was an error in Splus 5.1, released in 1999 and I don't have an older version handy right now. Current behavior is > 1:10 + 0:1 [1] 1 3 3 5 5 7 7 9 9 11 > 1:10 + 0:2 Problem in 1:10 + 0:2: length of longer operan

[Rd] simplify2array edge case

2012-10-11 Thread William Dunlap
Should simplify2array(higher=TRUE) treat 1 by 1 matrices differently than others? I expected a 3-dimensional array from all of the following 3 examples, not just the last 2. > str(simplify2array(list(array(11,c(1,1)), array(21,c(1,1))), higher=TRUE)) num [1:2] 11 21 > str(simplify2array(l

Re: [Rd] setting option in function

2012-10-19 Thread William Dunlap
Hi Charley, You can use the idiom oldNaAction <- options(na.action=na.fail) on.exit(options(oldNaAction)) or the slightly safer (protected again an interrupt between the first two lines or an error calling options to set them) oldNaAction <- getOption("na.action") on.exit(options(oldNa

Re: [Rd] Non-recursive way to remove empty directory on Windows?

2012-11-28 Thread William Dunlap
> (even worse, path may contain '..' or > likewise from a list.files(all.names=TRUE) call) Would anyone's code break if "." and ".." were never in the output of list.files() (or dir())? I find it tedious to skip them whenever doing anything recursive in the file system. They are not in the outpu

Re: [Rd] Stand alone application using R

2012-12-05 Thread William Dunlap
Would you mind elaborating on how rJava and RCaller "are not useful after a certain extent"? I.e., are there bugs, memory leaks, too limited an API, or other problems with them? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-devel-boun...@r-project

[Rd] svd(X, LINPACK=TRUE) alters its input

2012-12-06 Thread William Dunlap
Ordinary functions should not alter their inputs but in R-2.15.2 svd(LINPACK=TRUE,X) does. (It worked in 2.15.0 but not in 2.15.1 or 2.15.2 and became deprecated in 2.15.2.) > X <- matrix(c(1,2,3, 5,7,11, 13,17,19), 3, 3) > X [,1] [,2] [,3] [1,]15 13 [2,]27 17 [3,]3

Re: [Rd] Comments in the DESCRIPTION file

2012-12-06 Thread William Dunlap
Why not just use some tag that R doesn't already use, say "Comment:", instead of a #? If you allow # in position one of a line to mean a comment then people may expect # to be used as a comment anywhere on a line. (It may also mess up some dcf parsing code that I've written - it checks that line

Re: [Rd] stringsAsFactors

2013-02-11 Thread William Dunlap
Note that changing this does not just mean getting rid of "silly warnings". Currently, predict.lm() can give wrong answers when stringsAsFactors is FALSE. > d <- data.frame(x=1:10, f=rep(c("A","B","C"), c(4,3,3)), y=c(1:4, 15:17, 28.1,28.8,30.1)) > fit_ab <- lm(y ~ x + f, data = d, subset = f

Re: [Rd] Printing of anonymous functions in calls is sub-optimal

2013-02-16 Thread William Dunlap
> I suspect it's only when you have a function in the quoted call, not a symbol: Add a call to 'function' (as opposed to the function made by evaluating that call) to your test suite: > Q <- list( q1 = quote(getFunction("-")(x)), q2 = substitute(f(x), list(f = function(x) {-x

Re: [Rd] Running R scripts with interactive-style evaluation

2013-02-26 Thread William Dunlap
Which part of the read-eval-print loop loop ("REPL loop") do you need? source(file, print=TRUE) gives you the printing part, which is what I usually want. Opening a file connection and repeatedly calling parse(n=1) gives you the read part, > tf <- tempfile() > cat(file=tf, sep="\n", "x <- 1

[Rd] duplicate export entries in NAMESPACE

2013-03-12 Thread William Dunlap
Circa 80 CRAN and core-R packages have duplicate export entries in their NAMESPACE files. E.g., bit 1.1.9 : c("as.bit", "as.bitwhich", "as.which", "physical", "virtual") forecast 4.1 : "forecast.lm" graphics 2.15.3 : "barplot" mcmc 0.9.1 : "morph" RCurl 1.95.3 : "curlOptions" util

Re: [Rd] Deprecating partial matching in $.data.frame

2013-03-20 Thread William Dunlap
Will you be doing the same for attribute names? > options(prompt=with(version, paste0(language,"-",major,".",minor,"> "))) R-2.15.3> x <- structure(17, AnAttr="an attribute", Abcd="a b c d") R-2.15.3> attr(x, "A") NULL R-2.15.3> attr(x, "An") [1] "an attribute" R-2.15.3> attr(x, "Ab"

[Rd] POSIXt oddness at end of 1969

2013-04-17 Thread William Dunlap
A user here noticed the following difference between Linux and Windows versions of R-2.15.3 (and R-3.0.0, I think) when using times within a second of the end of 1969: f <- function (sec = -1) { x1 <- as.POSIXct(c(2 * sec, sec, 0), origin = "1970-01-01", tz = "UTC") x2 <- as.POSIXlt(x1)

Re: [Rd] as.name and namespaces

2013-04-24 Thread William Dunlap
Hi Pat, You could use substitute(), > mycall <- quote(list(lm(Y ~ x1), lm(Y ~ x2))) > do.call("substitute", list(mycall, list(lm=quote(stats::lm list(stats::lm(Y ~ x1), stats::lm(Y ~ x2)) The do.call is necessary because substitute() does not evaluate its first argument and we want 'myc

Re: [Rd] multiple issues with is.unsorted()

2013-04-24 Thread William Dunlap
>>>> is.unsorted(NA) >>> [1] NA >>> => Contradicts "all objects of length 0 or 1 are sorted". > > Ok. I really think we should change the above. > If NA is for a missing number, it still cannot be unsorted if it > is of length one. > > --> the above will give FALSE "real soon now".

[Rd] objects with tsp attribute but no class

2013-05-01 Thread William Dunlap
What is the intended difference between objects of class "ts", which must have an attribute called "tsp", and objects with that attribute but not that class? Calling time series oriented functions like time() or window() on vectors of numbers produce the classless objects with the tsp attribute.

[Rd] problem in add1's F statistic when data contains NAs?

2013-05-14 Thread William Dunlap
Shouldn't the F statistic (and p value) for the x2 term in the following calls to anova() and add1() be the same? I think anova() gets it right and add1() does not. > d <- data.frame(y=1:10, x1=log(1:10), x2=replace(1/(1:10), 2:3, NA)) > anova(lm(y ~ x1 + x2, data=d)) Analysis of Variance Table

Re: [Rd] Objects created by more than one data call?

2013-05-21 Thread William Dunlap
If you look at data(package="Ecat")$results[,"Item"] you will see the items "Hstarts", "Hstarts (Intratesm)", and "Hstarts (Intratesq)" which I think means that the dataset Hstarts is found in 3 .rda files, "Hstarts.rda", "Intratesq.rda", and "Intratesm.rda". There are duplicate, modulo (file

Re: [Rd] Objects created by more than one data call?

2013-05-22 Thread William Dunlap
t; all.equal(envViet$MedExp, envMed$MedExp) [1] "Names: 11 string mismatches" [2] "Length mismatch: comparison on first 11 components" [3] "Component 1: 'current' is not a factor" ... [18] &qu

Re: [Rd] Inconsistent results from .C()

2013-05-22 Thread William Dunlap
Had you tried using the new-to-3.0.0 options(CBoundCheck=TRUE)? [from the NEWS file] There is a new option, options(CBoundsCheck=), which controls how .C() and .Fortran() pass arguments to compiled code. If true (which can be enabled by setting the environment variable R_C_BOUNDS_C

Re: [Rd] Assigning NULL to large variables is much faster than rm() - any reason why I should still use rm()?

2013-05-25 Thread William Dunlap
Another way to avoid using rm() in loops is to use throw-away functions. E.g., > t3 <- system.time(for (k in 1:ncol(x)) { # your last, fastest, example + a <- x[,k] + colSum <- sum(a) + a <- NULL # Not needed anymore + b <- x[k,] + rowSum <- sum(b) + b <- NULL # Not needed anymore + }

Re: [Rd] R-3.0.1 - "transient" make check failure in splines-EX.r

2013-05-30 Thread William Dunlap
>> identical(ns(x, df = 2), ns(x, df = 2, knots = NULL)) > [1] FALSE >> identical(ns(x, df = 2), ns(x, df = 2, knots = NULL)) > [1] TRUE If you used a function like identicalOrReturnInputs <- function(x, y) { if (identical(x, y)) { TRUE } else { list(x=x, y=y)

[Rd] anyDuplicated(incomp=NA) fails

2009-05-08 Thread William Dunlap
With today's R 2.10.0(devel) I get: > anyDuplicated(c(1,NA,3,NA,5), incomp=NA) # expect 0 Warning: stack imbalance in 'anyDuplicated', 20 then 21 Warning: stack imbalance in '.Internal', 19 then 20 Warning: stack imbalance in '{', 17 then 18 [1] 0 > anyDuplicated(c(1,NA,3,NA,3), incomp=NA) # expec

[Rd] file descriptor leak in getSrcLines in R 2.10.0 svn 48590

2009-05-21 Thread William Dunlap
I noticed the following file descriptor leak when I couldn't remove a package unless I shut down the R session that had loaded and used it. The function that triggered the problem printed the output of a call to parse(). Each time one prints a srcref a connection is opened and not closed. It loo

Re: [Rd] file descriptor leak in getSrcLines in R 2.10.0 svn 48590

2009-05-22 Thread William Dunlap
> ... > The idea is that if the srcfile is already open, then it > should be left > open; but if it is not open, it should be closed at the end. > open() on > an open srcfile is supposed to make no change to the srcfile, just > return the already open connection. > > > (It looks like the sr

Re: [Rd] [R] split strings

2009-05-28 Thread William Dunlap
Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com > -Original Message- > From: r-devel-boun...@r-project.org > [mailto:r-devel-boun...@r-project.org] On Behalf Of Wacek Kusnierczyk > Sent: Thursday, May 28, 2009 5:30 AM > Cc: R help project; r-devel@r-project.org; A

[Rd] reference counting bug: overwriting for loop 'seq' variable

2009-06-01 Thread William Dunlap
It looks like the 'seq' variable to 'for' can be altered from within the loop, leading to incorrect answers. E.g., in the following I'd expect 'sum' to be 1+2=3, but R 2.10.0 (svn 48686) gives 44.5. > x = c(1,2); sum = 0; for (i in x) { x[i+1] = i + 42.5; sum = sum + i }; sum [1] 44.5 or,

<    1   2   3   4   5   >