Re: [Rd] Telling Windows how to find DLL's from R?

2010-07-13 Thread Thomas Baier
Dominick,

Dominick Samperi wrote:
> On Fri, Jul 9, 2010 at 3:48 PM, Duncan Murdoch
> wrote: 
> 
>> On 09/07/2010 2:38 PM, Dominick Samperi wrote:
>> 
>>> Is it possible to set Windows' search path from within R, or to tell 
>>> Windows how to find a DLL in some other way from R? Specifically, if 
>>> a package DLL depends on another DLL the normal requirement is that 
>>> the second DLL be in the search path so Windows can find it (there 
>>> are other tricks, but they apply at the Windows level, not at the R 
>>> level).
>>> 
>>> 
>> 
>> 
>> I haven't tried this, but can't you use Sys.setenv() to change the 
>> PATH to what you want?  Presumably you'll want to change it back 
>> afterwards.
>> 
> 
> Thanks, good suggestion, but it does not seem to work. If PATH is 
> updated in this way the change is local to the current process, not to 
> the top-level Windows process, so a subsequent
> dyn.load('foo.dll') will fail if foo.dll depends on bar.dll, unless 
> bar.dll is placed in the search path for the top-level shell. Seems 
> like this needs to be done as part of system startup outside of R.
> 
> On the other hand, if foo.dll is the package library for package foo, 
> and if foo depends on package bar, then there is no need to place 
> bar.dll in the top-level search path. R takes care of this (more
> typical) situation.   

there is another Windows "feature" which will do the trick for you without
modifying the search path. Windows normally only loads DLLs once, so this
means if you first load the dependent DLL (manually, e.g. using dyn.load())
then the already loaded DLL will be used instead of trying to load one from
path.

E.g. in your example:

dyn.load("mypath/bar.dll")
dyn.load("foo.dll")

will work, as bar.dll (a dependency of foo.dll) is already loaded.

Thomas

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


[Rd] Bug in acf function?

2010-07-13 Thread Steve Jones
I'm using R-2.9.1, so forgive me if this has already been resolved.

One element of the object returned from the acf function is n.used,
described in the man page as "The number of observations in the time
series".

However, I've noticed that this value is set to nrow(x) via the sampleT
variable, i.e. the number of rows in the passed-in series. This forces
an assumption that all rows of the series contain values.

Since it's possible to calculate an acf from an incomplete series by
passing 'na.action=na.pass', I would suggest that the value of n.used in
this instance should be set to 'sum(!is.na(series))'.

This has knock-on effects too: the plot produced by the acf function
includes a horizontal line showing the threshold of statistical
significance, which is dependent on the number of measurements in the
series:

qnorm((1 + 0.95)/2)/sqrt(corr$n.used)

For a given set of time series of fixed length, the threshold is
therefore constant regardless of the number of valid measurements in the
series, which I believe to be incorrect.

As a side note, I also think that this significance threshold should be
returned as part of the output of the acf function - as it stands, the
value is shown in a plot but there's no way to actually get the value.

Steve.



signature.asc
Description: OpenPGP digital signature
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] S4 class extends "data.frame", getDataPart sees "list"

2010-07-13 Thread John Chambers

On 7/11/10 9:08 PM, Daniel Murphy wrote:

R-Devel:

When I get the data part of an S4 class that contains="data.frame", it gives
me a list, even when the "data.frame" is the S4 version:


d<-data.frame(x=1:3)
isS4(d)

[1] FALSE   # of course

dS4<-new("data.frame",d)
isS4(dS4)

[1] TRUE# ok

class(dS4)

[1] "data.frame"   # good
attr(,"package")
[1] "methods"

setClass("A", representation(label="character"), contains="data.frame")

[1] "A"

a<-new("A",dS4, label="myFrame")
getDataPart(a)

[[1]]  # oh?
[1] 1 2 3


class(a...@.data)

[1] "list"   # hmm

names(a)

[1] "x" # sure, that makes sense

a

Object of class "A"
   x
1 1
2 2
3 3
Slot "label":
[1] "myFrame"


Was I wrong to have expected the "data part" of 'a' to be a "data.frame"?


Yes.  Also, there is a clue in the documentation for getDataPart: 
"rarely suitable to be called directly"

The data part, aka "data slot", generally does not have a class (S4 or S3).

You are probably looking for S3Part():

> setClass("myFrame", contains = "data.frame")
[1] "myFrame"
> z = new("myFrame", data.frame(x=1:3))
> z
Object of class "myFrame"
  x
1 1
2 2
3 3
> S3Part(z)
Object of class "data.frame"
  x
1 1
2 2
3 3
> S3Part(z, strictS3 = TRUE)
  x
1 1
2 2
3 3





Thanks.

Dan Murphy

[[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] S4 class extends "data.frame", getDataPart sees "list"

2010-07-13 Thread Daniel Murphy
Thank you. For "getDataPart" I was following (my interpretation of) advice
from the documentation for "Classes": The functions
getDataPart
 and setDataPart  are
a cleaner, but essentially equivalent way to deal with the data part.
I interpreted "cleaner" to mean "preferred." From your reply, John, it
sounds like I should go back to the obj...@.data construct.
-Dan
On Tue, Jul 13, 2010 at 5:57 AM, John Chambers  wrote:

> On 7/11/10 9:08 PM, Daniel Murphy wrote:
>
>> R-Devel:
>>
>> When I get the data part of an S4 class that contains="data.frame", it
>> gives
>> me a list, even when the "data.frame" is the S4 version:
>>
>>  d<-data.frame(x=1:3)
>>> isS4(d)
>>>
>> [1] FALSE   # of course
>>
>>> dS4<-new("data.frame",d)
>>> isS4(dS4)
>>>
>> [1] TRUE# ok
>>
>>> class(dS4)
>>>
>> [1] "data.frame"   # good
>> attr(,"package")
>> [1] "methods"
>>
>>> setClass("A", representation(label="character"), contains="data.frame")
>>>
>> [1] "A"
>>
>>> a<-new("A",dS4, label="myFrame")
>>> getDataPart(a)
>>>
>> [[1]]  # oh?
>> [1] 1 2 3
>>
>>  class(a...@.data)
>>>
>> [1] "list"   # hmm
>>
>>> names(a)
>>>
>> [1] "x" # sure, that makes sense
>>
>>> a
>>>
>> Object of class "A"
>>   x
>> 1 1
>> 2 2
>> 3 3
>> Slot "label":
>> [1] "myFrame"
>>
>>
>> Was I wrong to have expected the "data part" of 'a' to be a "data.frame"?
>>
>
> Yes.  Also, there is a clue in the documentation for getDataPart: "rarely
> suitable to be called directly"
> The data part, aka "data slot", generally does not have a class (S4 or S3).
>
> You are probably looking for S3Part():
>
> > setClass("myFrame", contains = "data.frame")
> [1] "myFrame"
> > z = new("myFrame", data.frame(x=1:3))
> > z
> Object of class "myFrame"
>
>  x
> 1 1
> 2 2
> 3 3
> > S3Part(z)
> Object of class "data.frame"
>
>  x
> 1 1
> 2 2
> 3 3
> > S3Part(z, strictS3 = TRUE)
>
>  x
> 1 1
> 2 2
> 3 3
>
>
>
>
>> Thanks.
>>
>> Dan Murphy
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> 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] S4 class extends "data.frame", getDataPart sees "list"

2010-07-13 Thread John Chambers


On 7/13/10 8:43 AM, Daniel Murphy wrote:

Thank you. For "getDataPart" I was following (my interpretation of)
advice from the documentation for "Classes": The functions |getDataPart
| and
|setDataPart |
are a cleaner, but essentially equivalent way to deal with the data part.
I interpreted "cleaner" to mean "preferred." From your reply, John, it
sounds like I should go back to the obj...@.data construct.


No, that's not the distinction.  Preferred for what, is the question. In 
order for a class to extend a basic type, it has to have that type. 
Then the .Data "slot" is a sort of fiction needed for the metadata.
(Because of some "features" of R implementation, it's not quite that 
simple.  Matrices act like a basic type, and some types, such as 
"environment" require a second kludge.)



If you really want that slot, the advice holds, but only because there 
is no actual ".Data" slot (i.e., attribute).


But you weren't talking about that at all.  In fact (just to contradict 
my previous mail) you probably wanted to turn your object into a 
data.frame.  If so, best to say so:


> as(z, "data.frame")
Object of class "data.frame"
  x
1 1
2 2
3 3

and, for that matter:

> as(z, "list")
[[1]]
[1] 1 2 3


-Dan
On Tue, Jul 13, 2010 at 5:57 AM, John Chambers mailto:j...@r-project.org>> wrote:

On 7/11/10 9:08 PM, Daniel Murphy wrote:

R-Devel:

When I get the data part of an S4 class that
contains="data.frame", it gives
me a list, even when the "data.frame" is the S4 version:

d<-data.frame(x=1:3)
isS4(d)

[1] FALSE   # of course

dS4<-new("data.frame",d)
isS4(dS4)

[1] TRUE# ok

class(dS4)

[1] "data.frame"   # good
attr(,"package")
[1] "methods"

setClass("A", representation(label="character"),
contains="data.frame")

[1] "A"

a<-new("A",dS4, label="myFrame")
getDataPart(a)

[[1]]  # oh?
[1] 1 2 3

class(a...@.data)

[1] "list"   # hmm

names(a)

[1] "x" # sure, that makes sense

a

Object of class "A"
   x
1 1
2 2
3 3
Slot "label":
[1] "myFrame"


Was I wrong to have expected the "data part" of 'a' to be a
"data.frame"?


Yes.  Also, there is a clue in the documentation for getDataPart:
"rarely suitable to be called directly"
The data part, aka "data slot", generally does not have a class (S4
or S3).

You are probably looking for S3Part():

 > setClass("myFrame", contains = "data.frame")
[1] "myFrame"
 > z = new("myFrame", data.frame(x=1:3))
 > z
Object of class "myFrame"

  x
1 1
2 2
3 3
 > S3Part(z)
Object of class "data.frame"

  x
1 1
2 2
3 3
 > S3Part(z, strictS3 = TRUE)

  x
1 1
2 2
3 3




Thanks.

Dan Murphy

[[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] S4 class extends "data.frame", getDataPart sees "list"

2010-07-13 Thread Daniel Murphy
OK, I see. Thanks.
-Dan

On Tue, Jul 13, 2010 at 9:11 AM, John Chambers  wrote:

>
> On 7/13/10 8:43 AM, Daniel Murphy wrote:
>
>> Thank you. For "getDataPart" I was following (my interpretation of)
>> advice from the documentation for "Classes": The functions |getDataPart
>> | and
>> |setDataPart |
>>
>> are a cleaner, but essentially equivalent way to deal with the data part.
>> I interpreted "cleaner" to mean "preferred." From your reply, John, it
>> sounds like I should go back to the obj...@.data construct.
>>
>
> No, that's not the distinction.  Preferred for what, is the question. In
> order for a class to extend a basic type, it has to have that type. Then the
> .Data "slot" is a sort of fiction needed for the metadata.
> (Because of some "features" of R implementation, it's not quite that
> simple.  Matrices act like a basic type, and some types, such as
> "environment" require a second kludge.)
>
>
> If you really want that slot, the advice holds, but only because there is
> no actual ".Data" slot (i.e., attribute).
>
> But you weren't talking about that at all.  In fact (just to contradict my
> previous mail) you probably wanted to turn your object into a data.frame.
>  If so, best to say so:
>
> > as(z, "data.frame")
>
> Object of class "data.frame"
>  x
> 1 1
> 2 2
> 3 3
>
> and, for that matter:
>
> > as(z, "list")
> [[1]]
> [1] 1 2 3
>
>  -Dan
>> On Tue, Jul 13, 2010 at 5:57 AM, John Chambers > > wrote:
>>
>>On 7/11/10 9:08 PM, Daniel Murphy wrote:
>>
>>R-Devel:
>>
>>When I get the data part of an S4 class that
>>contains="data.frame", it gives
>>me a list, even when the "data.frame" is the S4 version:
>>
>>d<-data.frame(x=1:3)
>>isS4(d)
>>
>>[1] FALSE   # of course
>>
>>dS4<-new("data.frame",d)
>>isS4(dS4)
>>
>>[1] TRUE# ok
>>
>>class(dS4)
>>
>>[1] "data.frame"   # good
>>attr(,"package")
>>[1] "methods"
>>
>>setClass("A", representation(label="character"),
>>contains="data.frame")
>>
>>[1] "A"
>>
>>a<-new("A",dS4, label="myFrame")
>>getDataPart(a)
>>
>>[[1]]  # oh?
>>[1] 1 2 3
>>
>>class(a...@.data)
>>
>>[1] "list"   # hmm
>>
>>names(a)
>>
>>[1] "x" # sure, that makes sense
>>
>>a
>>
>>Object of class "A"
>>   x
>>1 1
>>2 2
>>3 3
>>Slot "label":
>>[1] "myFrame"
>>
>>
>>Was I wrong to have expected the "data part" of 'a' to be a
>>"data.frame"?
>>
>>
>>Yes.  Also, there is a clue in the documentation for getDataPart:
>>"rarely suitable to be called directly"
>>The data part, aka "data slot", generally does not have a class (S4
>>or S3).
>>
>>You are probably looking for S3Part():
>>
>> > setClass("myFrame", contains = "data.frame")
>>[1] "myFrame"
>> > z = new("myFrame", data.frame(x=1:3))
>> > z
>>Object of class "myFrame"
>>
>>  x
>>1 1
>>2 2
>>3 3
>> > S3Part(z)
>>Object of class "data.frame"
>>
>>  x
>>1 1
>>2 2
>>3 3
>> > S3Part(z, strictS3 = TRUE)
>>
>>  x
>>1 1
>>2 2
>>3 3
>>
>>
>>
>>
>>Thanks.
>>
>>Dan Murphy
>>
>>[[alternative HTML version deleted]]
>>
>>__
>>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] Severe memory problem using split()

2010-07-13 Thread cstrato

Dear Martin,

Thank you for this explanation.

Best regards
Christian


On 7/13/10 12:31 AM, Martin Morgan wrote:

On 07/12/2010 03:00 PM, cstrato wrote:

Dear Martin,

Thank you, you are right, now I get:


ann<- read.delim("Hu6800_ann.txt", stringsAsFactors=FALSE)
object.size(ann)

2035952 bytes

u2p<- split(ann[,"ProbesetID"],ann[,"UNIT_ID"])
object.size(u2p)

1207368 bytes

object.size(unlist(u2p))

865176 bytes

Nevertheless, a size of 1.2MB for a list representing 2 of 11 columns of


but it's a list of length(unique(ann[["UNIT_ID"]]))) elements, each of
which has a pointer to the element, a pointer to the name of the
element, and the element data itself. I'd guess it adds up in a
non-mysterious way. For a sense of it (and maybe only understandable if
you have a working understanding of how R represents data) see, e.g.,


.Internal(inspect(list(x=1,y=2)))

@1a4c538 19 VECSXP g0c2 [ATT] (len=2, tl=0)
   @191cad8 14 REALSXP g0c1 [] (len=1, tl=0) 1
   @191caa8 14 REALSXP g0c1 [] (len=1, tl=0) 2
ATTRIB:
   @16fc8d8 02 LISTSXP g0c0 []
 TAG: @60cf18 01 SYMSXP g0c0 [MARK,NAM(2),gp=0x4000] "names"
 @1a4c500 16 STRSXP g0c2 [] (len=2, tl=0)
   @674e88 09 CHARSXP g0c1 [MARK,gp=0x21] "x"
   @728c38 09 CHARSXP g0c1 [MARK,gp=0x21] "y"

Martin


a table of size 754KB seems still to be pretty large?

Best regards
Christian


On 7/12/10 11:44 PM, Martin Morgan wrote:

On 07/12/2010 01:45 PM, cstrato wrote:

Dear all,

With great interest I followed the discussion:
https://stat.ethz.ch/pipermail/r-devel/2010-July/057901.html
since I have currently a similar problem:

In a new R session (using xterm) I am importing a simple table
"Hu6800_ann.txt" which has a size of 754KB only:


ann<- read.delim("Hu6800_ann.txt")
dim(ann)

[1] 7129   11


When I call "object.size(ann)" the estimated memory used to store "ann"
is already 2MB:


object.size(ann)

2034784 bytes


Now I call "split()" and check the estimated memory used which turns out
to be 3.3GB:


u2p<- split(ann[,"ProbesetID"],ann[,"UNIT_ID"])
object.size(u2p)

3323768120 bytes


I guess things improve with stringsAsFactors=FALSE in read.delim?

Martin



During the R session I am running "top" in another xterm and can see
that the memory usage of R increases to about 550MB RSIZE.


Now I do:


object.size(unlist(u2p))

894056 bytes

It takes about 3 minutes to complete this call and the memory usage of R
increases to about 1.3GB RSIZE. Furthermore, during evaluation of this
function the free RAM of my Mac decreases to less than 8MB free PhysMem,
until it needs to swap memory. When finished, free PhysMem is 734MB but
the size of R increased to 577MB RSIZE.

Doing "split(ann[,"ProbesetID"],ann[,"UNIT_ID"],drop=TRUE)" did not
change the object.size, only processing was faster and it did use less
memory on my Mac.

Do you have any idea what the reason for this behavior is?
Why is the size of list "u2p" so large?
Do I make any mistake?


Here is my sessionInfo on a MacBook Pro with 2GB RAM:


sessionInfo()

R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
[1] C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

Best regards
Christian
_._._._._._._._._._._._._._._._._._
C.h.r.i.s.t.i.a.n   S.t.r.a.t.o.w.a
V.i.e.n.n.a   A.u.s.t.r.i.a
e.m.a.i.l:cstrato at aon.at
_._._._._._._._._._._._._._._._._._

__
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] Building a custom Windows installer

2010-07-13 Thread John Fox
Dear r-devel list members,

It's been several years since I last built a custom Windows installer for R,
and despite my notes and the instructions in Sections 3.1.7 and D.4 of the R
Installation and Administration Manual, I've run into a problem, receiving
the following error message:

--- snip ---

C:\R\src\R-2.11.1\src\gnuwin32\installer>make myR IMAGEDIR=c:/temp/R-2.11.1
MDISDI=1
Makefile:3: ../MkRules: No such file or directory
make: ../fixed/rwver.pl: Command not found
make: ../fixed/rwver.pl: Command not found
make: ../fixed/rwver.pl: Command not found
make: ../fixed/rwver.pl: Command not found
make: *** No rule to make target `../MkRules'.  Stop.

--- snip ---

My path looks like this:

--- snip ---

C:\R\src\R-2.11.1\src\gnuwin32\installer>set path
Path=c:\Rtools\bin;c:\Rtools\perl\bin;c:\Rtools\MinGW\bin;C:\Program
Files\Commo
n Files\Microsoft Shared\Windows Live;C:\GTK\bin;C:\Program
Files\Insightful\spl
us80\;C:\Program Files\ActiveState Komodo Edit
4\;.;c:\R\R-2.11.1\bin;C:\progra~
1\miktex~1.7\miktex\bin;c:\progra~1\htmlhe~1;C:\Windows\system32;C:\Windows;
C:\W
indows\System32\Wbem;C:\Program Files\Common Files\Roxio
Shared\DLLShared\;C:\Pr
ogram Files\GnuWin32\bin;C:\Program Files\CollabNet Subversion;C:\Program
Files\
MySQL\MySQL Server 5.1\bin;C:\Program Files\SAS\Shared
Files\Formats;C:\Program
Files\TortoiseSVN\bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Fil
es\Smart Projects\IsoBuster;C:\Program Files\MiKTeX
2.7\miktex\bin\;C:\Program F
iles\QuickTime\QTSystem\;C:\Program Files\Common Files\Microsoft
Shared\Windows
Live;C:\Program Files\SSH Communications Security\SSH Secure
Shell;C:\Program Fi
les\Bibtex2html;C:\Graphviz2.20\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

--- snip ---

The directory c:/temp/R-2.11.1 contains a complete customized installation
of R, while C:\R\src\R-2.11.1 contains the unpacked R sources. This is on a
Windows Vista system. I've updated Rtools to version 2.11.  I can supply
more information, but I'm not sure what's relevant. 

I don't think that I should have to place a MkRules file in the gnuwin32
directory, but I tried copying each the MkRules.dist and MkRules.rules files
there in turn to MkRules. Neither worked; I apparently got farther copying
MkRules.rules to MkRules, but eventually got another error:

--- snip ---

C:\R\src\R-2.11.1\src\gnuwin32\installer>make myR IMAGEDIR=c:/temp/R-2.11.1
MDISDI=1
echo "make.packages.html(.Library)" | c:/temp/R-2.11.1/bin/rterm --vanilla
--sla
ve LC_COLLATE=C
Making packages.html ... done
adding MD5 checksums
perl JRins.pl R-2.11.1 c:/temp/R-2.11.1 1 1 0 R-core
"/iscc" R.iss > myR.log
/iscc: not found
make: *** [myR] Error 127 

--- snip ---

Any help would be appreciated.

John


John Fox
Senator William McMaster 
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox

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


Re: [Rd] Suggestion for serialization performance improvement on Windows

2010-07-13 Thread Henrik Bengtsson
On Fri, Jul 9, 2010 at 6:49 AM, Bryan W. Lewis  wrote:
> Dear R developers,
>
>  The slow performance of serializing to a raw vector on Windows is an
> issue that has appeared in this list before.

My guess is that you are referring to:

[Rd] serialize() to via temporary file is heaps faster than doing it
directly (on Windows), 2008-07-24
http://tolstoy.newcastle.edu.au/R/e4/devel/08/07/2355.html

If so, that thread show how unnecessarily slow (5 mins instead of 5
secs) it is on Windows.

> It appears to be due to
> the frequent use of realloc from the resize_buffer method in
> serialize.c.
>
> I suggest a more granular, but still incremental, re-allocation of
> memory. For example change near the top of resize_buffer to:
>
> R_size_t newsize = needed + 65536 - (needed % 65536);
>
> or some other similar small multiple of a typical system page size.
>
> I have found this to dramatically improve performance of serialization
> to raw vectors on Windows.

I second this update, which seems to make serialize(...,
connection=NULL) useful in Windows.

Thxs,

Henrik

>
> Best,
>
> Bryan
>
> __
> 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