[Rd] lapply version with [ subseting - a suggestion

2010-09-21 Thread Vitaly S.

Dear R developers,

Reviewing my code, I have realized that about 80% of the time in the lapply I
need to access the names of the objects inside the loop.

In such cases I iterate over indexes or names:
lapply(names(x), ... [i]), 
lapply(seq_along(x),  ... x[[i]] ... names(x)[i] ), or
for(i in seq_along(x)) ...

which is rather inconvenient.

How about an argument to lapply which would specify the [ or [[ subseting to use
in the splitting of the vector?
Or may be a different set of functions lapply1,
sapply1?

I believe this pattern is rather common for other users as well.

Thanks.
VS.

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


Re: [Rd] Check for updates under Windows (Was: a reliable way to check the latest version of R on CRAN?)

2010-09-21 Thread Barry Rowlingson
On Sat, Sep 18, 2010 at 11:17 PM, Yihui Xie  wrote:
> Dear R developers,
>
> I asked this question in r-help list but have not got a definite
> solution yet, and I think it might be more appropriate to ask
> developers or CRAN maintainers directly. Many software packages often
> have a menu item like "Check for updates" under the "Help" menu, e.g.
> Filezilla and Firefox, and I believe it is also necessary for R (at
> least for R GUI under Windows). Note all users really have to update
> R, but we should make it clearer to them that new versions are
> available. Yes, they can go to R homepage to check by themselves, but
> my experience tells me it is rarely the case. Therefore, I wish RGui
> could gain a new menu to check for updates of R. Thanks very much!

Something like this:

 winMenuAdd("Updates"); winMenuAddItem("Updates","R
Version","require(gtools);checkRVersion()")

Barry

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


Re: [Rd] lapply version with [ subseting - a suggestion

2010-09-21 Thread Michael Lawrence
On Tue, Sep 21, 2010 at 3:55 AM, Vitaly S.  wrote:

>
> Dear R developers,
>
> Reviewing my code, I have realized that about 80% of the time in the lapply
> I
> need to access the names of the objects inside the loop.
>
> In such cases I iterate over indexes or names:
> lapply(names(x), ... [i]),
> lapply(seq_along(x),  ... x[[i]] ... names(x)[i] ), or
> for(i in seq_along(x)) ...
>
> which is rather inconvenient.
>
> How about an argument to lapply which would specify the [ or [[ subseting
> to use
> in the splitting of the vector?
> Or may be a different set of functions lapply1,
> sapply1?
>
>
I'm not sure what you want exactly, but  what about just using mapply over
the names and vector elements?


> I believe this pattern is rather common for other users as well.
>
> Thanks.
> VS.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

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


Re: [Rd] lapply version with [ subseting - a suggestion

2010-09-21 Thread Henrique Dallazuanna
See ?vapply also

On Tue, Sep 21, 2010 at 7:55 AM, Vitaly S.  wrote:

>
> Dear R developers,
>
> Reviewing my code, I have realized that about 80% of the time in the lapply
> I
> need to access the names of the objects inside the loop.
>
> In such cases I iterate over indexes or names:
> lapply(names(x), ... [i]),
> lapply(seq_along(x),  ... x[[i]] ... names(x)[i] ), or
> for(i in seq_along(x)) ...
>
> which is rather inconvenient.
>
> How about an argument to lapply which would specify the [ or [[ subseting
> to use
> in the splitting of the vector?
> Or may be a different set of functions lapply1,
> sapply1?
>
> I believe this pattern is rather common for other users as well.
>
> Thanks.
> VS.
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

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


Re: [Rd] Possible bug or annoyance with library.dynam.unload()

2010-09-21 Thread Karl Forner
Hello,

I got no reply on this issue.
It is not critical and I could think of work-around, but it really looks
like a bug to me.
Should I file a bug-report instead of posting in this list ?

Thanks,

Karl

On Thu, Sep 16, 2010 at 6:11 PM, Karl Forner  wrote:

> Hello,
>
> I have a package with a namespace. Because I use Roxygen that overwrites
> the NAMESPACE file each time it is run, I use a R/zzz.R file with
> an .onLoad() and .onUnload() functions to take care of loading and
> unloading my shared library.
>
> The problem: if I load my library from a local directory, then the
> unloading of the package fails, e.g:
>
> # loads fine
> >library(Foo, lib.loc=".Rcheck")
>
> >unloadNamespace("Foo")
> Warning message:
> .onUnload failed in unloadNamespace() for 'Foo', details:
>   call: library.dynam.unload("Foo", libpath)
>   error: shared library 'Foo' was not loaded
>
> # I traced it a little:
> >library.dynam.unload("Foo", ".Rcheck/Foo")
> Error in library.dynam.unload("Foo", ".Rcheck/Foo") :
>   shared library 'Foo' was not loaded
>
> # using an absolute path works
> >library.dynam.unload("Foo", "/home/toto/.Rcheck/Foo")
>
>
> So from what I understand, the problem is either that the relative libpath
> is sent to the .onUnload() function instead of the absolute one,
> or that library.dynam.unload() should be modified to handle the relative
> paths.
>
> Am I missing something ? What should I do ?
>
> Thanks,
>
>
> Karl
>

[[alternative HTML version deleted]]

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


Re: [Rd] Possible bug or annoyance with library.dynam.unload()

2010-09-21 Thread Duncan Murdoch

 On 21/09/2010 10:38 AM, Karl Forner wrote:

Hello,

I got no reply on this issue.
It is not critical and I could think of work-around, but it really looks
like a bug to me.
Should I file a bug-report instead of posting in this list ?


I'd probably post instructions for a reproducible example first.  Pick 
some CRAN package, tell us what to do with it to trigger the error, and 
then we can see if it's something special about your package or Roxygen 
or a general problem.


Duncan Murdoch


Thanks,

Karl

On Thu, Sep 16, 2010 at 6:11 PM, Karl Forner  wrote:

>  Hello,
>
>  I have a package with a namespace. Because I use Roxygen that overwrites
>  the NAMESPACE file each time it is run, I use a R/zzz.R file with
>  an .onLoad() and .onUnload() functions to take care of loading and
>  unloading my shared library.
>
>  The problem: if I load my library from a local directory, then the
>  unloading of the package fails, e.g:
>
>  # loads fine
>  >library(Foo, lib.loc=".Rcheck")
>
>  >unloadNamespace("Foo")
>  Warning message:
>  .onUnload failed in unloadNamespace() for 'Foo', details:
>call: library.dynam.unload("Foo", libpath)
>error: shared library 'Foo' was not loaded
>
>  # I traced it a little:
>  >library.dynam.unload("Foo", ".Rcheck/Foo")
>  Error in library.dynam.unload("Foo", ".Rcheck/Foo") :
>shared library 'Foo' was not loaded
>
>  # using an absolute path works
>  >library.dynam.unload("Foo", "/home/toto/.Rcheck/Foo")
>
>
>  So from what I understand, the problem is either that the relative libpath
>  is sent to the .onUnload() function instead of the absolute one,
>  or that library.dynam.unload() should be modified to handle the relative
>  paths.
>
>  Am I missing something ? What should I do ?
>
>  Thanks,
>
>
>  Karl
>

[[alternative HTML version deleted]]

__
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] lapply version with [ subseting - a suggestion

2010-09-21 Thread Vitalie Spinu
>> How about an argument to lapply which would specify the [ or [[ subseting
>> to use
>> in the splitting of the vector?
>> Or may be a different set of functions lapply1,
>> sapply1?
>>
>>
> I'm not sure what you want exactly, but  what about just using mapply over
> the names and vector elements?
>

General rule for "[[" operator is to extract the atomic part of the object.
"[" instead returns an object of the same type as original.

Just imagine an S4 objects with multiple parallel vectors as slots. My "["
extracts an object of the same class as the original, but now, in each slot
is an element with length one.

With current tools in R one can not loop through such an object easily. If a
version of "lapply" would exist which would split the original object with
"[" the problem would be solved.

Thanks for the tip on mapply, works for the names indeed. Never occurred to
me, ashamed.

>
>
>> I believe this pattern is rather common for other users as well.
>>
>> Thanks.
>> VS.
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>

[[alternative HTML version deleted]]

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


Re: [Rd] Check for updates under Windows (Was: a reliable way to check the latest version of R on CRAN?)

2010-09-21 Thread Yihui Xie
Yes, that's more or less what I mean. Thanks!

Maybe this functionality can be added to src/gnuwin32/rui.c

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Tue, Sep 21, 2010 at 6:54 AM, Barry Rowlingson
 wrote:
> On Sat, Sep 18, 2010 at 11:17 PM, Yihui Xie  wrote:
>> Dear R developers,
>>
>> I asked this question in r-help list but have not got a definite
>> solution yet, and I think it might be more appropriate to ask
>> developers or CRAN maintainers directly. Many software packages often
>> have a menu item like "Check for updates" under the "Help" menu, e.g.
>> Filezilla and Firefox, and I believe it is also necessary for R (at
>> least for R GUI under Windows). Note all users really have to update
>> R, but we should make it clearer to them that new versions are
>> available. Yes, they can go to R homepage to check by themselves, but
>> my experience tells me it is rarely the case. Therefore, I wish RGui
>> could gain a new menu to check for updates of R. Thanks very much!
>
> Something like this:
>
>  winMenuAdd("Updates"); winMenuAddItem("Updates","R
> Version","require(gtools);checkRVersion()")
>
> Barry
>

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


[Rd] Speeding up squaring of vectors

2010-09-21 Thread Radford Neal
I see that some of the speed patches that I posted have been
incorporated into the current development version (eg, my patch-for,
patch-evalList, and patch-vec-arith).

My patch for speeding up x^2 has been addressed in an inadvisable way,
however.  This was a simple addition of four lines of code that speeds
up squaring of real vectors by a factor of about six (for vectors of
length 1), by just converting x^2 to x*x.  Modifications in the
current development version (r52936 and r52937) attempt to address
this issue in a different way, but they produce a smaller speedup. My
modification is about 2.6 faster than the current development version
(on an Intel/Linux system).  Similarly, in the current development
version, x*x is still about 2.6 times faster than x^2.  Furthermore,
the modification in the current development version slows down
exponentiation by 0.5 (square roots) by about 4%.

I think there's no reason not to just use my patch.  One could also
put in a similar modification to speed up squaring of integer vectors,
but I think that is a much less common operation than squaring of real
vectors, which arises all the time when computing squared residuals,
squared Euclidean distances, etc.

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


[Rd] trouble compiling RMySQL (and others) for 64 bit windows.

2010-09-21 Thread Ted Byers
I have a 64 bit machine running 64 bit windows 7 pro, 64 bit MySQL, and 64
bit R 2.11.1.

I have also installed RTools for 64 bit windows for this version of R
(archive name is oldWin64toolchain.zip; the install path for its contents
is C:\RTools, if that matters).  I can open up a commandline window and
invoke any of the programs in both bin directories (both added to the system
path).
There are several packages for which I could not find 64 bit binaries
RMySQL, RPostgreSQL, RQRMlib, &c.  While I don't have time at present to
develop ne packages for R, these packages are things I routinely use on my
32 bit machine (where, thankfully, all seems to be working fine).
Therefore, my only interest is in getting or making the 64 bit binaries for
these packages so I can duplicate on the new 64 bit machine what I had been
doing on the old 32 bit machine.

Note, I routinely develop new software using MS VS (originally v 6, and then
VS 2005, and now vs 2010), and if I need to work up code to run on some
flavour of unix, I use the cygwin environment.  Therefore, I have no qualms
about compiling programs I use from source.  I just prefer not to if there
is already a binary distribution for whatever platform I happen to be using.

I began by trying to follow the instructions provided on
http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL, and found a couple
issues.



First, there was no Renviron.site in C:/Program Files/R/R-2.11.1-x64/etc so
I made one and placed in it the following:

MYSQL_HOME=C:\PROGRA~1\MySQL\MYSQLS~1.1

The full path to the installation of MySQL is: C:\Program Files\MySQL\MySQL
Server 5.1

Unlike what is said on the biostat.mc.vanderbilt.edu pages, MYSQL_HOME is
still empty:


> Sys.getenv('MYSQL_HOME')
MYSQL_HOME
""
This is when I start R AFTER having made the Renviron.site file.

Something I notice, though, that may have a bearing on this is that although
Emacs finds my new Renviron.site file when I navigate to that directory, it
does not appear in Windows Explorer.  I am wondering if Windows 7 is somehow
blocking access to it.  If that guess is correct, the question becomes, how
do I fix that?  If it isn't correct, what should I check?  This is not an
insurmountable problem, though as I can always set that environment variable
at the beginning of a session.  I do that already on other systems that are
32 bit clients that have to talk to 64 bit servers.  It is just mildly
disturbing that R does not seem to know about the Renviron.site file I made
for it.

Second, I read in the instructions the following:


> 3. *Re-start R and execute install.packages('RMySQL',type='source')* at
> the R prompt.
>
> As long as you followed the above steps correctly, 
> RMySQLwill install cleanly and you 
> will be able to immediately load it and use it.
>
However, when I follow this instruction I get:
> install.packages('RMySQL',type='source')
Warning in install.packages("RMySQL", type = "source") :
  argument 'lib' is missing: using
'C:\Users\Ted\Documents/R/win64-library/2.11'
--- Please select a CRAN mirror for use in this session ---
trying URL 'http://probability.ca/cran/src/contrib/RMySQL_0.7-5.tar.gz'
Content type 'application/x-gzip' length 160769 bytes (157 Kb)
opened URL
downloaded 157 Kb
* installing *source* package 'RMySQL' ...
Warning in system("sh ./configure.win") : sh not found
ERROR: configuration failed for package 'RMySQL'
* removing 'C:/Users/Ted/Documents/R/win64-library/2.11/RMySQL'
The downloaded packages are in
‘C:\Users\Ted\AppData\Local\Temp\Rtmp7xg8yb\downloaded_packages’
Warning message:
In install.packages("RMySQL", type = "source") :
  installation of package 'RMySQL' had non-zero exit status
>

It is clearly failing before it could choke on the MYSQL_HOME value.  On
reading it, it is no surprise to me that it failed to find sh as I recognize
that as one of several unix shells.  What I don't know is how I should alter
the instructions provided on the vanderbilt site so that the install works
on Windows 7.  I know I have access to sh in cygwin, but I really don't want
to confound my cygwin environment with what I use for R.

While I have not used RTools before, I would assume that whatever issues I
am presently facing would impact any package for which I need to build 64
bit binaries for Windows 7.  So what do I need to know in order to
effectively use RTools on compiling an arbitrary package, perhaps using
RMySQL as an example (since that is the first one I need to compile).

Thanks

Ted

[[alternative HTML version deleted]]

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


[Rd] Crash report: regexpr("a{2-}", "")

2010-09-21 Thread Henrik Bengtsson
Each of the following calls crash ("core dumps") R (R --vanilla) on
various versions and OSes:

regexpr("a{2-}", "")
sub("a{2-}", "")
gsub("a{2-}", "")


EXAMPLES:

> sessionInfo()
R version 2.11.1 Patched (2010-09-16 r52949)
Platform: i386-pc-mingw32 (32-bit)
...
> regexpr("a{2-}", "")
Assertion failed: iter->max == -1 || iter->max == 1, file
tre-compile.c, line 1825
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

> sessionInfo()
R version 2.12.0 Under development (unstable) (2010-09-14 r52910)
Platform: i386-pc-mingw32/i386 (32-bit)
...
> regexpr("a{2-}", "")
Assertion failed: iter->max == -1 || iter->max == 1, file
tre-compile.c, line 1825
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


> sessionInfo()
R version 2.11.0 Patched (2010-05-09 r51960)
x86_64-unknown-linux-gnu
...
> regexpr("a{2-}", "")
R: tre-compile.c:1825: tre_ast_to_tnfa: Assertion `iter->max == -1 ||
iter->max == 1' failed.
Aborted


/Henrik

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


Re: [Rd] Crash report: regexpr("a{2-}", "")

2010-09-21 Thread David Winsemius


On Sep 21, 2010, at 11:04 PM, Henrik Bengtsson wrote:


Each of the following calls crash ("core dumps") R (R --vanilla) on
various versions and OSes:

regexpr("a{2-}", "")
sub("a{2-}", "")
gsub("a{2-}", "")


EXAMPLES:


sessionInfo()

R version 2.11.1 Patched (2010-09-16 r52949)
Platform: i386-pc-mingw32 (32-bit)
...

regexpr("a{2-}", "")

Assertion failed: iter->max == -1 || iter->max == 1, file
tre-compile.c, line 1825
This application has requested the Runtime to terminate it in an  
unusual way.

Please contact the application's support team for more information.


sessionInfo()

R version 2.12.0 Under development (unstable) (2010-09-14 r52910)
Platform: i386-pc-mingw32/i386 (32-bit)
...

regexpr("a{2-}", "")

Assertion failed: iter->max == -1 || iter->max == 1, file
tre-compile.c, line 1825
This application has requested the Runtime to terminate it in an  
unusual way.

Please contact the application's support team for more information.



sessionInfo()

R version 2.11.0 Patched (2010-05-09 r51960)
x86_64-unknown-linux-gnu
...

regexpr("a{2-}", "")

R: tre-compile.c:1825: tre_ast_to_tnfa: Assertion `iter->max == -1 ||
iter->max == 1' failed.
Aborted


Not a problem in reasonably current Mac with 64bit GUI:
> regexpr("a{2-}", "")
[1] 1
attr(,"match.length")
[1] 0
> sub("a{2-}", "")
Error in is.character(x) : 'x' is missing
> gsub("a{2-}", "")
Error in is.character(x) : 'x' is missing

R version 2.11.1 Patched (2010-08-26 r52822)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
[R.app GUI 1.35 (5612) x86_64-apple-darwin9.8.0]

--
David.



/Henrik

__
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] Crash report: regexpr("a{2-}", "")

2010-09-21 Thread Henrik Bengtsson
David's post made me realize that I got the sub()/gsub() lines wrong.
It should be:

regexpr("a{2-}", "")
sub("a{2-}", "", "")
gsub("a{2-}", "", "")

Either way, the crash is there, at on least Windows and Linux.

/Henrik

On Tue, Sep 21, 2010 at 8:43 PM, David Winsemius  wrote:
>
> On Sep 21, 2010, at 11:04 PM, Henrik Bengtsson wrote:
>
>> Each of the following calls crash ("core dumps") R (R --vanilla) on
>> various versions and OSes:
>>
>> regexpr("a{2-}", "")
>> sub("a{2-}", "")
>> gsub("a{2-}", "")
>>
>>
>> EXAMPLES:
>>
>>> sessionInfo()
>>
>> R version 2.11.1 Patched (2010-09-16 r52949)
>> Platform: i386-pc-mingw32 (32-bit)
>> ...
>>>
>>> regexpr("a{2-}", "")
>>
>> Assertion failed: iter->max == -1 || iter->max == 1, file
>> tre-compile.c, line 1825
>> This application has requested the Runtime to terminate it in an unusual
>> way.
>> Please contact the application's support team for more information.
>>
>>> sessionInfo()
>>
>> R version 2.12.0 Under development (unstable) (2010-09-14 r52910)
>> Platform: i386-pc-mingw32/i386 (32-bit)
>> ...
>>>
>>> regexpr("a{2-}", "")
>>
>> Assertion failed: iter->max == -1 || iter->max == 1, file
>> tre-compile.c, line 1825
>> This application has requested the Runtime to terminate it in an unusual
>> way.
>> Please contact the application's support team for more information.
>>
>>
>>> sessionInfo()
>>
>> R version 2.11.0 Patched (2010-05-09 r51960)
>> x86_64-unknown-linux-gnu
>> ...
>>>
>>> regexpr("a{2-}", "")
>>
>> R: tre-compile.c:1825: tre_ast_to_tnfa: Assertion `iter->max == -1 ||
>> iter->max == 1' failed.
>> Aborted
>
> Not a problem in reasonably current Mac with 64bit GUI:
>> regexpr("a{2-}", "")
> [1] 1
> attr(,"match.length")
> [1] 0
>> sub("a{2-}", "")
> Error in is.character(x) : 'x' is missing
>> gsub("a{2-}", "")
> Error in is.character(x) : 'x' is missing
>
> R version 2.11.1 Patched (2010-08-26 r52822)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> [R.app GUI 1.35 (5612) x86_64-apple-darwin9.8.0]
>
> --
> David.
>>
>>
>> /Henrik
>>
>> __
>> 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
>

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


Re: [Rd] Crash report: regexpr("a{2-}", "")

2010-09-21 Thread David Winsemius


On Sep 22, 2010, at 12:12 AM, Henrik Bengtsson wrote:


David's post made me realize that I got the sub()/gsub() lines wrong.
It should be:

regexpr("a{2-}", "")
sub("a{2-}", "", "")
gsub("a{2-}", "", "")



Still no crash on a Mac. Did you mean to include a third argument to  
regexpr() as you did for sub and gsub?


--
David.

Either way, the crash is there, at on least Windows and Linux.

/Henrik

On Tue, Sep 21, 2010 at 8:43 PM, David Winsemius > wrote:


On Sep 21, 2010, at 11:04 PM, Henrik Bengtsson wrote:


Each of the following calls crash ("core dumps") R (R --vanilla) on
various versions and OSes:

regexpr("a{2-}", "")
sub("a{2-}", "")
gsub("a{2-}", "")


EXAMPLES:


sessionInfo()


R version 2.11.1 Patched (2010-09-16 r52949)
Platform: i386-pc-mingw32 (32-bit)
...


regexpr("a{2-}", "")


Assertion failed: iter->max == -1 || iter->max == 1, file
tre-compile.c, line 1825
This application has requested the Runtime to terminate it in an  
unusual

way.
Please contact the application's support team for more information.


sessionInfo()


R version 2.12.0 Under development (unstable) (2010-09-14 r52910)
Platform: i386-pc-mingw32/i386 (32-bit)
...


regexpr("a{2-}", "")


Assertion failed: iter->max == -1 || iter->max == 1, file
tre-compile.c, line 1825
This application has requested the Runtime to terminate it in an  
unusual

way.
Please contact the application's support team for more information.



sessionInfo()


R version 2.11.0 Patched (2010-05-09 r51960)
x86_64-unknown-linux-gnu
...


regexpr("a{2-}", "")


R: tre-compile.c:1825: tre_ast_to_tnfa: Assertion `iter->max == -1  
||

iter->max == 1' failed.
Aborted


Not a problem in reasonably current Mac with 64bit GUI:

regexpr("a{2-}", "")

[1] 1
attr(,"match.length")
[1] 0

sub("a{2-}", "")

Error in is.character(x) : 'x' is missing

gsub("a{2-}", "")

Error in is.character(x) : 'x' is missing

R version 2.11.1 Patched (2010-08-26 r52822)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
[R.app GUI 1.35 (5612) x86_64-apple-darwin9.8.0]

--
David.



/Henrik

__
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



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


Re: [Rd] Crash report: regexpr("a{2-}", "")

2010-09-21 Thread Henrik Bengtsson
On Tue, Sep 21, 2010 at 9:20 PM, David Winsemius  wrote:
>
> On Sep 22, 2010, at 12:12 AM, Henrik Bengtsson wrote:
>
>> David's post made me realize that I got the sub()/gsub() lines wrong.
>> It should be:
>>
>> regexpr("a{2-}", "")
>> sub("a{2-}", "", "")
>> gsub("a{2-}", "", "")
>>
>
> Still no crash on a Mac. Did you mean to include a third argument to
> regexpr() as you did for sub and gsub?

No, it was only that sub()/gsub() needs at least three arguments while
regexpr() only needs two, and did a simple cut'n'paste when I wrote
the original message.  All three commands probably use the same
underlying regular expression library, so it is likely it is same bug.

It looks like at least on your OS/R version it does not crash.

/Henrik

>
> --
> David.
>>
>> Either way, the crash is there, at on least Windows and Linux.
>>
>> /Henrik
>>
>> On Tue, Sep 21, 2010 at 8:43 PM, David Winsemius 
>> wrote:
>>>
>>> On Sep 21, 2010, at 11:04 PM, Henrik Bengtsson wrote:
>>>
 Each of the following calls crash ("core dumps") R (R --vanilla) on
 various versions and OSes:

 regexpr("a{2-}", "")
 sub("a{2-}", "")
 gsub("a{2-}", "")


 EXAMPLES:

> sessionInfo()

 R version 2.11.1 Patched (2010-09-16 r52949)
 Platform: i386-pc-mingw32 (32-bit)
 ...
>
> regexpr("a{2-}", "")

 Assertion failed: iter->max == -1 || iter->max == 1, file
 tre-compile.c, line 1825
 This application has requested the Runtime to terminate it in an unusual
 way.
 Please contact the application's support team for more information.

> sessionInfo()

 R version 2.12.0 Under development (unstable) (2010-09-14 r52910)
 Platform: i386-pc-mingw32/i386 (32-bit)
 ...
>
> regexpr("a{2-}", "")

 Assertion failed: iter->max == -1 || iter->max == 1, file
 tre-compile.c, line 1825
 This application has requested the Runtime to terminate it in an unusual
 way.
 Please contact the application's support team for more information.


> sessionInfo()

 R version 2.11.0 Patched (2010-05-09 r51960)
 x86_64-unknown-linux-gnu
 ...
>
> regexpr("a{2-}", "")

 R: tre-compile.c:1825: tre_ast_to_tnfa: Assertion `iter->max == -1 ||
 iter->max == 1' failed.
 Aborted
>>>
>>> Not a problem in reasonably current Mac with 64bit GUI:

 regexpr("a{2-}", "")
>>>
>>> [1] 1
>>> attr(,"match.length")
>>> [1] 0

 sub("a{2-}", "")
>>>
>>> Error in is.character(x) : 'x' is missing

 gsub("a{2-}", "")
>>>
>>> Error in is.character(x) : 'x' is missing
>>>
>>> R version 2.11.1 Patched (2010-08-26 r52822)
>>> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>>> [R.app GUI 1.35 (5612) x86_64-apple-darwin9.8.0]
>>>
>>> --
>>> David.


 /Henrik

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

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


[Rd] On the median

2010-09-21 Thread Bill.Venables
I have recently become aware of some curious behaviour of median() which I 
think could be usefully corrected.  I am sure this must have come up before, 
but I'm raising it again.

The phenomenon is best shown by a simple example.

> d <- matrix(runif(4*4), 4, 4)
> d
  [,1]   [,2]   [,3]  [,4]
[1,] 0.1388592 0.08478220 0.02012404 0.7733054
[2,] 0.1718332 0.06370432 0.66167219 0.2521809
[3,] 0.3190116 0.08616569 0.23107320 0.6278422
[4,] 0.9185233 0.29218144 0.99193823 0.6306847
> apply(d, 1, median)
[1] 0.1118207 0.2120070 0.2750424 0.7746040

So far, so good. But what happens when you turn it into a data frame?

> d <- data.frame(d)
> apply(d, 1, median)
[1] 0.1118207 0.2120070 0.2750424 0.7746040

No problem there, yet.  But if you just look at one row:

> median(d[1, ])
[1] 0.0847822 0.1388592

without warning you get a vector of size two as the result, viz the two values 
which enclose the middle.  I thought this was simply because one row of a data 
frame is a list, but that can't be the whole story.  e.g.

> median(d[,1])
[1] 0.2454224
> median(as.list(d[,1]))
Error in sort.list(x, partial = half + 0L:1L) : 
  'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
> 

(Well yes, Brian, I did...)  

The function mean() has a nice property when you call it on a data frame, e.g.

> mean(d)
   X1X2X3X4 
0.3870568 0.1317084 0.4762019 0.5710033 

and just to complicate the issue even further, 

> mean(d[1, ])
X1 X2 X3 X4 
0.13885916 0.08478220 0.02012404 0.77330535 

On the other hand, median(), whose behaviour should be similar I would suggest, 
just fails when handed a data frame argument.

> median(d)
[1] NA NA
Warning messages:
1: In mean.default(X[[1L]], ...) :
  argument is not numeric or logical: returning NA
2: In mean.default(X[[2L]], ...) :
  argument is not numeric or logical: returning NA
> 
_

I suggest that there should be some consistency here, and I suggest that 
median() be given a data.frame method that would allow it to respond much the 
same as mean() does.  The way it responds to data frame arguments now is 
quirky, at best.

Currently median() though generic, has only the default method.

> methods("mean")
[1] mean.data.frame mean.Date   mean.defaultmean.difftime   
mean.POSIXct   
[6] mean.POSIXlt   

> methods("median")
[1] median.default
> 

Perhaps quantile() should also have a data.frame method for the same reason.  
To me it seems curious, too, that quantile has a POSIXt method (in the stats 
package) whereas median currently does not.  (mean.POSIX*t are in the base 
package.)

> methods("quantile")
[1] quantile.default quantile.POSIXt*

   Non-visible functions are asterisked
> 

How do people respond to this?

(I see there have been hints of this in the past, see 
http://tolstoy.newcastle.edu.au/R/e2/help/06/12/7692.html
but I could only find hints.)

Bill Venables
CSIRO/CMIS, Cleveland Labs.
 
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] OT: Reason/history behind ## notation for comments?

2010-09-21 Thread Henrik Bengtsson
Off topic, but since I've observe both styles, does anyone know the
history behind/reason for using ## instead of a single # to start
comments in R.  I know some editors do this by default.  Is it because
in C it is easier to distinguish (search/replace/...) comments from C
preprocessor directives such as #include, and that's became a de facto
standard elsewhere?

/Henrik

PS. I don't want to get into a debate on what's the best style.

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