Re: [Rd] suggestion/request: install.packages and unnecessary file modifications

2009-03-19 Thread Martin Maechler
Thank you, Mark,

I've now committed (a version of) your suggestion to R-devel
(destined to become R 2.9.0 on April 17).

Martin Maechler, ETH Zurich

>   
> on Tue, 10 Mar 2009 21:52:30 +1100 writes:

> Dear R-devel
> When 'install.packages' runs, it updates all html files in all packages. 
Mostly, there seems to be no actual change to the html file contents, but the 
date/time does change. This has causing been me a bit of trouble, because I 
keep synchronized versions of R on several different machines, and whenever I 
install a package, many MB of file transfers are required; my slow upload link 
can't cope.

> The culprit appears to be 'utils:::fixup.package.URLs'. Adding the 
commented lines below, near the end of the function, avoids the unnecessary 
rewrite.

> Mark Bravington
> CSIRO
> Hobart
> Australia

> for (f in files) {
> page <- readLines(f)
> old.page <- page # MVB
> page <- gsub(olddoc, doc, page, fixed = TRUE, useBytes = TRUE)
> page <- gsub(oldbase, base, page, fixed = TRUE, useBytes = TRUE)
> page <- gsub(oldutils, utils, page, fixed = TRUE, useBytes = TRUE)
> page <- gsub(oldgraphics, graphics, page, fixed = TRUE, 
> useBytes = TRUE)
> page <- gsub(oldstats, stats, page, fixed = TRUE, useBytes = TRUE)
> page <- gsub(olddata, datasets, page, fixed = TRUE, useBytes = TRUE)
> page <- gsub(oldgrD, grD, page, fixed = TRUE, useBytes = TRUE)
> page <- gsub(oldmeth, meth, page, fixed = TRUE, useBytes = TRUE)
> if( identical( page, old.page)) # MVB
> next # MVB
> out <- try(file(f, open = "w"), silent = TRUE)
> if (inherits(out, "try-error")) {
> warning(gettextf("cannot update '%s'", f), domain = NA)
> next
> }
> writeLines(page, out)
> close(out)
> }
> return(TRUE)
> }

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

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


Re: [Rd] [R] incoherent conversions from/to raw

2009-03-19 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote:
> interestingly,
>
> c(1, as.raw(1))
> # error: type 'raw' is unimplemented in 'RealAnswer'
>
>   

three more comments.


(1)
the above is interesting in the light of what ?c says:

"
The output type is determined from the highest type of the
 components in the hierarchy NULL < raw < logical < integer < real
 < complex < character < list < expression.
"

which seems to suggest that raw components should be coerced to whatever
the highest type among all arguments to c, which clearly doesn't happen:

test = function(type)
c(as.raw(1), get(sprintf('as.%s',type))(1))

for (type in c('null', 'logical', 'integer', 'real', 'complex',
'character', 'list', 'expression'))
   tryCatch(test(type), error = function(e) cat(sprintf("raw won't
coerce to %s type\n", type)))

which shows that raw won't coerce to the four first types in the
'hierarchy' (excluding NULL), but it will to character, list, and
expression.

suggestion:   improve the documentation, or adapt the implementation to
a more coherent design.



(2)
incidentally, there's a bug somewhere there related to the condition
system and printing:

tryCatch(stop(), error=function(e) print(e))
# works just fine

tryCatch(stop(), error=function(e) sprintf('%s', e))
# *** caught segfault ***
# address (nil), cause 'memory not mapped'

# Traceback:
# 1: sprintf("%s", e)
# 2: value[[3]](cond)
# 3: tryCatchOne(expr, names, parentenv, handlers[[1]])
# 4: tryCatchList(expr, classes, parentenv, handlers)
# 5: tryCatch(stop(), error = function(e) sprintf("%s", e))

# Possible actions:
# 1: abort (with core dump, if enabled)
# 2: normal R exit
# 3: exit R without saving workspace
# 4: exit R saving workspace
# Selection:
 
interestingly, it is possible to stay in the session by typing ^C.  the
session seems to work, but if the tryCatch above is tried once again, a
segfault causes r to crash immediately:

# ^C
tryCatch(stop(), error=function(e) sprintf('%s', e))
# [whoe...@wherever] $

however, this doesn't happen if some other code is evaluated first:

# ^C
x = 1:10^8
tryCatch(stop(), error=function(e) sprintf('%s', e))
# Error in sprintf("%s", e) : 'getEncChar' must be called on a CHARSXP
  
this can't be a feature.  (tried in both 2.8.0 and r-devel;  version
info at the bottom.)

suggestion:  trace down and fix the bug.



(3)
the error argument to tryCatch is used in two examples in ?tryCatch, but
it is not explained anywhere in the help page.  one can guess that the
argument name corresponds to the class of conditions the handler will
handle, but it would be helpful to have this stated explicitly.  the
help page simply says:

"
   If a condition is signaled while evaluating 'expr' then
 established handlers are checked, starting with the most recently
 established ones, for one matching the class of the condition.
 When several handlers are supplied in a single 'tryCatch' then the
 first one is considered more recent than the second. 
"

which is uninformative in this respect -- what does 'one matching the
class' mean?

suggestion:  improve the documentation.

vQ


> version
   _  
platform   i686-pc-linux-gnu  
arch   i686   
os linux-gnu  
system i686, linux-gnu
status
major  2  
minor  8.0
year   2008   
month  10 
day20 
svn rev46754  
language   R  
version.string R version 2.8.0 (2008-10-20)



> version
  
_  
platform  
i686-pc-linux-gnu  
arch  
i686   
os
linux-gnu  
system i686,
linux-gnu
status Under development
(unstable)   
major 
2  
minor 
9.0
year  
2009   
month 
03 
day   
19 
svn rev   
48152  
language  
R  
version.string R version 2.9.0 Under development (unstable) (2009-03-19
r48152)


Re: [Rd] R does not compile any more on FreeBSD 8.0-CURRENT

2009-03-19 Thread Hiroyuki Kawakatsu
Rainer Hurling wrote:
> On a recent FreeBSD 8.0-CURRENT (i386) building R (any version)
> breaks with the following messages:
[...]

I run 7.1-RELEASE (amd64) so I cannot comment on any potential issues
with 8.0-CURRENT. On my machine the r-devel tarball (r48148) builds
without any problems but I use

./configure MAKE=gmake

Have you tried gmake?

h.
-- 
+---
| Hiroyuki Kawakatsu
| Business School, Dublin City University
| Dublin 9, Ireland. Tel +353 (0)1 700 7496

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


Re: [Rd] using R with java

2009-03-19 Thread Bilel
Hi,
>
> I am a java programmer, an I want to use R from java.
> could so help me
> thanks for telling me whether I 'm using the good mailing list.
>
> thanks!!
>
>
>


-- 
Bilel

[[alternative HTML version deleted]]

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


Re: [Rd] sprintf("%d", integer(0)) aborts

2009-03-19 Thread Prof Brian Ripley

On Wed, 18 Mar 2009, William Dunlap wrote:


In R's sprintf() if any of the arguments has length 0
the function aborts.  E.g.,

  > sprintf("%d", integer(0))
  Error in sprintf("%d", integer(0)) : zero-length argument
  > sprintf(character(), integer(0))
  Error in sprintf(character(), integer(0)) :
'fmt' is not a non-empty character vector

This comes up in code like
  x[nchar(x)==0] <- sprintf("No. %d", seq_along(x)[nchar(x)==0])
which works if x contains any empty strings
  x<-c("One","Two","") # changes "" -> "No. 3"
but not if it doesn't
  x<-c("One","Two","Three") # throws error instead of doing nothing

When I wrote S+'s sprintf() I had it act like the binary
arithmetic operators, returning a zero long result if any
argument were zero long.  (Otherwise its result is as long
as the longest input.)  I think it would be nice if R's
sprintf did this also.

Currently you must add defensive code (if (any(nchar(x)==0))...)
to make functions using sprintf to work in all cases and that
muddies up the code and slows things down.

Do you think this is a reasonable thing to do?  I've attached
a possible patch to src/main/sprintf.c makes the examples above
return character(0).


Yes.  It was deliberate that it works (and is documented) the way it 
is, and I've not previously seen any problematic examples.  But at 
least for the ... args, allowing zero-length arguments seems very 
reasonable.  I'm less convinced by zero-length formats, but the rule 
may be easier to explain if we allow them.


This will need a documentation change, and I'll look into it when I 
can.




Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com

---

Index: sprintf.c
===
--- sprintf.c   (revision 48148)
+++ sprintf.c   (working copy)
@@ -79,13 +79,13 @@
static R_StringBuffer outbuff = {NULL, 0, MAXELTSIZE};
Rboolean use_UTF8;

-outputString = R_AllocStringBuffer(0, &outbuff);
-
/* grab the format string */
nargs = length(args);
format = CAR(args);
-if (!isString(format) || length(format) == 0)
+if (!isString(format))
   error(_("'fmt' is not a non-empty character vector"));
+if (length(format) == 0)
+   return allocVector(STRSXP, 0) ;
args = CDR(args); nargs--;
if(nargs >= 100)
   error(_("only 100 arguments are allowed"));
@@ -97,9 +97,12 @@
for(i = 0; i < nargs; i++) {
   lens[i] = length(a[i]);
   if(lens[i] == 0)
-   error(_("zero-length argument"));
+   return allocVector(STRSXP, 0) ;
   if(maxlen < lens[i]) maxlen = lens[i];
}
+
+outputString = R_AllocStringBuffer(0, &outbuff);
+
if(maxlen % length(format))
   error(_("arguments cannot be recycled to the same length"));
for(i = 0; i < nargs; i++)



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [Rd] using R with java

2009-03-19 Thread Simon Urbanek


On Mar 19, 2009, at 7:33 , Bilel wrote:


Hi,


I am a java programmer, an I want to use R from java. could so help  
me thanks for telling me whether I 'm using the good mailing list.




There's rJava package for this and the mailing list for that package is
http://mailman.rz.uni-augsburg.de/mailman/listinfo/stats-rosuda-devel
so feel free to ask there for help.

Cheer,
Simon

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


Re: [Rd] sprintf("%d", integer(0)) aborts

2009-03-19 Thread William Dunlap

> -Original Message-
> From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] 
> Sent: Thursday, March 19, 2009 3:34 AM
> To: William Dunlap
> Cc: r-devel@r-project.org
> Subject: Re: [Rd] sprintf("%d", integer(0)) aborts
> 
> On Wed, 18 Mar 2009, William Dunlap wrote:
> 
> > In R's sprintf() if any of the arguments has length 0
> > the function aborts.  E.g.,
> >
> >   > sprintf("%d", integer(0))
> >   Error in sprintf("%d", integer(0)) : zero-length argument
> >   > sprintf(character(), integer(0))
> >   Error in sprintf(character(), integer(0)) :
> > 'fmt' is not a non-empty character vector
> >
> > This comes up in code like
> >   x[nchar(x)==0] <- sprintf("No. %d", seq_along(x)[nchar(x)==0])
> > which works if x contains any empty strings
> >   x<-c("One","Two","") # changes "" -> "No. 3"
> > but not if it doesn't
> >   x<-c("One","Two","Three") # throws error instead of doing nothing
> >
> > When I wrote S+'s sprintf() I had it act like the binary
> > arithmetic operators, returning a zero long result if any
> > argument were zero long.  (Otherwise its result is as long
> > as the longest input.)  I think it would be nice if R's
> > sprintf did this also.
> >
> > Currently you must add defensive code (if (any(nchar(x)==0))...)
> > to make functions using sprintf to work in all cases and that
> > muddies up the code and slows things down.
> >
> > Do you think this is a reasonable thing to do?  I've attached
> > a possible patch to src/main/sprintf.c makes the examples above
> > return character(0).
> 
> Yes.  It was deliberate that it works (and is documented) the way it 
> is, and I've not previously seen any problematic examples.

I was prompted to suggest the change by a note from Jim Holtman
in yesterday's R-help:

   > system.time({
   + x <- sample(5)  # test data
   + x[sample(5,1)] <- 'asdfasdf'  # characters strings
   + which.num <- grep("^[ 0-9]+$", x)  # find numbers
   + # convert to leading 0
   + x[which.num] <- sprintf("%018.0f", as.numeric(x[which.num]))
   + x[-which.num] <- toupper(x[-which.num])
   + })

This code failed when I converted it to a function to run
through sapply because then which.num was often integer(0).
When used in production it would probably work for a long time
before seeing a sample in which which.num was integer(0).
(Of course, it would then silently mess up on the next line,
x[-which.num]<-...)

>  But at 
> least for the ... args, allowing zero-length arguments seems very 
> reasonable.  I'm less convinced by zero-length formats, but the rule 
> may be easier to explain if we allow them.

Those were my thoughts as well.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

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