Re: [R] Are the error messages of ConstrOptim() consisten with each other?

2007-09-10 Thread Duncan Murdoch
ambda)))/lambda))-(pnorm(-sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*mat+lambda*lambda)/2.0+log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*mat+lambda*lambda))-((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))*pnorm(-sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*mat+lambda*lambda)/2.0-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/sqrt((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*mat+lambda*lambda)))*exp(-rint*mat)-(exp(rint*(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)*ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(!
 0.!
>  25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*
> (tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+!
 lb!
>  
> ar*(tot/sh*1000.0)))*sqrt(mat+(lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))-(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambda*lambda))^(-sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0+0.5)*pnorm(-log(((ss+(tot/sh*1000.0)*lbar)/(tot/sh*1000.0)/lbar*exp(lambd!
 a*!
>  lambda)))/((sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(
> sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0))+sqrt(0.25+2.0*rint/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0*(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))*sqrt((lambda*lambda/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))/(sigmae*ss/(ss+lbar*(tot/sh*1000.0)))
>
> apple.ana= function(rec1,lambda1,lbar1)
> {rec=rec1
> lambda=lambda1
> lbar=lbar1
> apple=eval(apple2)
> gradient=cbind(eval(D(apple2,'rec')),eval(D(apple2,'lambda')),
> eval(D(apple2,'lbar')))
> attr(apple.ana,'gradient')=gradient
> apple
> }
>
> fit.error=function(rec1,lambda1,lbar1)
> {rec=rec1
> lambda=lambda1
> lbar=lbar1
> sum((eval(apple2)*1000-orange)^2/(orange^2))
> }
>   

This is still coded incorrectly.  Objective functions optimize over the 
first parameter only.  See ?optim for the details.  constrOptim is just 
a wrapper for optim.

Duncan Murdoch
> fit.error.grr=function(rec1,lambda1,lbar1)
> {rec=rec1
> lambda=lambda1
> lbar=lbar1
>
> drec=sum(2*eval(D(apple2,'rec'))*(eval(apple2)*1-orange)/(orange^2))
> dlambda=sum(2*eval(D(apple2,'lambda'))*(eval(apple2)*1-orange)/(orange^2))
> dlbar=sum(2*eval(D(apple2,'lbar'))*(eval(apple2)*1-orange)/(orange^2))
>
> c(drec,dlambda,dlbar)
> }
>
> ui=matrix(c(1,-1,0,0,0,0,0,0,1,-1,0,0,0,0,0,0,1,-1),6,3)
> ci=c(0,-0.5,0,-2,0,-0.6)
>
> constrOptim(c(0.5,0.3,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
> constrOptim(c(0.5,0.9,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
> constrOptim(c(0.3,0.5,0.5), f=fit.error, gr=fit.error.grr, ui=ui,ci=ci)
>
> ###
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] mode or parameters of readBin

2007-09-10 Thread Duncan Murdoch
On 9/10/2007 10:26 AM, Sigbert Klinke wrote:
> Hi,
> 
>  > sapply(formals("readBin"), mode)
>   con  what n  sizesignedendian
>"name""name" "numeric" "logical" "logical""call"
> 
> returns for the mode of size logical. But in the documentation is said 
> that size should be integer. Does anyone know why the mode is logical?

The default value is NA, and the mode of NA is logical.  (It will 
automatically be promoted into another type if included in a vector, 
e.g. c(1:2, NA) promotes it to integer, c(3.14, NA) promotes it to numeric.)

More generally, I'd say reading the man page or the source is a better 
way to find out about the requirements for the arguments of a function.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] loop execution problem

2007-09-09 Thread Duncan Murdoch
On 09/09/2007 1:36 PM, kevinchang wrote:
> This is  bizzare. The for loop I set seems to go infinitly  because the
> hourglass cursor never disappers and I never get the result. But when I
> click on "X" of the window try to exit R, the execution finishes right after
> I abort exiting when RGui asks me to save the workplace or not.  Please help
> me out.

In Windows you can also abort execution by hitting Esc, or the menu 
entry "Misc|Stop current computation".

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave figure aspect ratio

2007-09-09 Thread Duncan Murdoch
On 09/09/2007 7:24 AM, Werner Wernersen wrote:
> Hello,
> 
> using Sweave, is there any option to preserve the
> original aspect ratio of plots generated from R code?
> 
> Consider this Sweave chunk:
> <>=
> x <- 1:10
> y <- sin(x)
> par(mar=c(4,4,0,4))
> plot(x,y,
>  xlab="x label",
>  ylab="y label"
>  )
> @
> 
> In Latex, I want to produce a plot of width 2 but
> don't care about the height. If I put the width and
> height like shown on the example, the box isn't square
> any more. But if I put only width or height in the
> Sweave option, then the values then the appearance is
> totally off. 
> 
> Is there any option for Sweave or other possibility to
> preserve the ratio of the sides of plots?

The width and height args in the header of the chunk are passed to the 
graphics device (postscript or pdf), but they don't appear in the LaTeX 
output.  To modify the appearance in LaTeX, you need to set a graphicx 
package parameter, e.g. something like

\setkeys{Gin}{width=2in}
<>=
x <- 1:10
y <- sin(x)
par(mar=c(4,4,0,4))
plot(x,y,
  xlab="x label",
  ylab="y label"
  )
@

If you only specify width, then the aspect ratio will be maintained.

The \setkeys{} changes are persistent; as far as I know there's no way 
to say "go back to the default" afterwards.  So what I'd suggest is to 
define a macro (e.g. \Gwidth) to give the default width, and then call

\setkeys{Gin}{width=\Gwidth}

at the start of your document and after any change like the one above.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What does it mean by "initial value not available"?

2007-09-09 Thread Duncan Murdoch
On 09/09/2007 7:01 AM, Yuchen Luo wrote:
> Dear friends.
> I use ConstrOptim( ) and got error message "initial value not available".
> My understanding of "initial value not available" is that one of the
> following 3 cases happens:
> 
> 1.The objective function is not well defined at the point of the initial
> value.
> 2. The differentiation of the objective function is not well defined at the
> point of the initial value.
> 3. The initial value violate the constrain of "ui %*% theta - ci >= 0"
> 
> But my situation does not belong to any of the above cases.
> 
> I have attached my code bellow and could you please help me take a look?

I haven't tried your code, but there's one obvious error:
...
> fit.error=function(rec,lambda,lbar)
> {sum((eval(apple)*1000-orange)^2/(orange^2))
> }

The function optimizes over the elements of the first parameter.  You've 
got two other parameters there, and I think you're trying to optimize 
over them as well.  Put them all into one vector.

The documentation for constrOptim doesn't make this as clear as it 
should; I'll clarify (by copying the docs from ?optim).

Duncan Murdoch

> 
> 
> fit.error.grr=function(rec,lambda, lbar)
> {drec=sum(eval(D(apple,'rec'))*(eval(apple)*1000-orange)/(orange^2))
> dlambda=sum(eval(D(apple,'lambda'))*(eval(apple)*1000-orange)/(orange^2))
> dlbar=sum(eval(D(apple,'lbar'))*(eval(apple)*1000-orange)/(orange^2))
> c(drec,dlambda,dlbar)
> }
> 
> 
> rr=c(4.33,4.22,4.27,4.43,4.43,4.44,4.45,4.65,4.77,4.77)
> tot=rep(13319.17,10)
> sh=rep(1553656,10)
> sigmae=c(0.172239074,0.188209271,0.193703774,0.172659891,0.164427247,
> 0.24602361,0.173555309,0.186701165,0.193150456)
> ss=c(56.49,56.39,56.55,57.49,57.37,55.02,56.02,54.35,54.09)
> orange=rep(21.25,10)
> 
> constrOptim(c(0.5,0.3,0.5), fit.error, fit.error.grr, ui=ui,ci=ci)
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plotting to stdout

2007-09-07 Thread Duncan Murdoch
On 9/7/2007 2:15 PM, Gene Selkov wrote:
> Thanks a ton, Duncan!
> 
> So I have verified that this line works:
> 
>echo "postscript(file=\"\", command=\"cat\"); plot(0)" | r --vanilla 
> --slave
> 
> Wonderful! (albeit a little unobvious)

I would include an explicit "dev.off()" after the plotting; I'm not sure 
all devices guarantee a clean shutdown when R quits.

Duncan Murdoch
> 
> --Gene
> 
> On Fri, 7 Sep 2007, Duncan Murdoch wrote:
> 
>> On 9/7/2007 12:36 PM, Gene Selkov wrote:
>>> I have found two prior instances of this question in R-help, but I can't 
>>> find the answer, and I'm giving up on mindless tinkering.
>>> 
>>>http://tolstoy.newcastle.edu.au/R/help/03a/5994.html
>>>https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html
>>> 
>>> I must be able to pipe the poltting commands to stdin and receive the plot 
>>> on stdout, with errors written to stderr, should any occur.
>>> 
>>> Here's what I tried:
>>> 
>>> file test.r:
>>> ~~
>>> postscript(stdout())
>>> plot(0)
>>> ~~
>>> 
>>> This command:
>>> 
>>> cat test.r | r --vanilla --slave
>>> 
>>> writes the output to a file named "1"
>>> 
>>> I have also tried:
>>> 
>>>postscript(file=stdout())
>>>postscript(file=file("stdout"))
>>> 
>>> In the latter case, the output goes to the file named "3".
>>> 
>>> Other graphics devices do the same thing.
>>> 
>>> It is interesting that write.table() supports the file=stdout() idiom. If 
>>> there is no official option to do this, I will appreciate a hint about the 
>>> spot in the code where I can fix it.
>>
>> The ?postscript man page suggests that
>>
>> postscript(file="", command="cat")
>>
>> should do what you want (or maybe something other than "cat" for the 
>> passthrough).  The file arg is described as a character string, not a 
>> connection, so I wouldn't expect stdout() to work.  For write.table(), the 
>> arg is defined to be either the name of a file or an open connection.
>>
>> Duncan Murdoch
>>
>>> 
>>> Thanks,
>>> 
>>> --Gene
>>> 
>>> ~
>>>> sessionInfo()
>>> R version 2.5.1 (2007-06-27)
>>> i386-apple-darwin8.10.1
>>> 
>>> locale:
>>> C
>>> 
>>> attached base packages:
>>> [1] "stats" "graphics"  "grDevices" "utils" "datasets"  "methods"
>>> [7] "base"
>>> 
>>> __
>>> R-help@stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide 
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Automatic detachment of dependent packages

2007-09-07 Thread Duncan Murdoch
On 9/7/2007 2:05 PM, Paul Smith wrote:
> On 9/7/07, Barry Rowlingson <[EMAIL PROTECTED]> wrote:
>> > When one loads certain packages, some other dependent packages are
>> > loaded as well. Is there some way of detaching them automatically when
>> > one detaches the first package loaded? For instance,
>> >
>> >> library(sqldf)
>> > Loading required package: RSQLite
>> > Loading required package: DBI
>> > Loading required package: gsubfn
>> > Loading required package: proto
>> >
>> > but
>> >
>> >> detach(package:sqldf)
>> >>
>> >> search()
>> >  [1] ".GlobalEnv""package:gsubfn""package:proto"
>> >  [4] "package:RSQLite"   "package:DBI"   "package:stats"
>> >  [7] "package:graphics"  "package:grDevices" "package:utils"
>> > [10] "package:datasets"  "package:methods"   "Autoloads"
>> > [13] "package:base"
>> >
>> > The packages
>> >
>> > RSQLite
>> > DBI
>> > gsubfn
>> > proto
>> >
>> > were not detached.
>>
>>   The danger here is that after attaching sqldf you might attach some
>> other package that needs, say, DBI, then when your cleanup routine
>> detaches DBI that other package dies because DBI isn't there.
>>
>>   The way to do it would be to detach any packages that are only
>> depended on by the package you are detaching. You'd have to call
>> packageDescription("foo", fields="Depends") for currently attached
>> packages to build the dependency tree and then work out which ones you
>> can remove... There's a bit of recursive tree-walking in there, but it
>> should be simple... Ummm...
> 
> Thanks, Barry and Gabor. Please, look at the following:
> 
>> library(sqldf)
> Loading required package: RSQLite
> Loading required package: DBI
> Loading required package: gsubfn
> Loading required package: proto
>> packageDescription("sqldf", fields="Depends")
> [1] "R (>= 2.5.1), RSQLite (>= 0.5-5), gsubfn"
>>
> 
> packageDescription does not mention the packages DBI and proto.

They are part of the recursive tree-walking that Barry mentioned, i.e. 
dependencies of RSQLite or gsubfn:

 > packageDescription("RSQLite", fields="Depends")
[1] "R (>= 2.3.0), methods, DBI (>= 0.2-3)"
 > packageDescription("gsubfn", fields="Depends")
[1] "R (>= 2.4.0), proto"

But you can get R to do the walking for you, using the pkgDepends 
function from the tools package:

 > pkgDepends("sqldf")
$Depends
[1] "DBI (>= 0.2-3)" "gsubfn" "methods"
[4] "proto"  "RSQLite (>= 0.5-5)"

... [ more stuff deleted ] ...

Watch out though:  you may not want to detach "methods" when you detach 
"sqldf", because it was already there.  Essentially you need some sort 
of snapshot of the state beforehand, and then you could restore it.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plotting to stdout

2007-09-07 Thread Duncan Murdoch
On 9/7/2007 12:36 PM, Gene Selkov wrote:
> I have found two prior instances of this question in R-help, but I can't 
> find the answer, and I'm giving up on mindless tinkering.
> 
>http://tolstoy.newcastle.edu.au/R/help/03a/5994.html
>https://stat.ethz.ch/pipermail/r-help/2004-December/062259.html
> 
> I must be able to pipe the poltting commands to stdin and receive the plot 
> on stdout, with errors written to stderr, should any occur.
> 
> Here's what I tried:
> 
> file test.r:
> ~~
> postscript(stdout())
> plot(0)
> ~~
> 
> This command:
> 
> cat test.r | r --vanilla --slave
> 
> writes the output to a file named "1"
> 
> I have also tried:
> 
>postscript(file=stdout())
>postscript(file=file("stdout"))
> 
> In the latter case, the output goes to the file named "3".
> 
> Other graphics devices do the same thing.
> 
> It is interesting that write.table() supports the file=stdout() idiom. If 
> there is no official option to do this, I will appreciate a hint 
> about the spot in the code where I can fix it.

The ?postscript man page suggests that

postscript(file="", command="cat")

should do what you want (or maybe something other than "cat" for the 
passthrough).  The file arg is described as a character string, not a 
connection, so I wouldn't expect stdout() to work.  For write.table(), 
the arg is defined to be either the name of a file or an open connection.

Duncan Murdoch

> 
> Thanks,
> 
> --Gene
> 
> ~
>> sessionInfo()
> R version 2.5.1 (2007-06-27)
> i386-apple-darwin8.10.1
> 
> locale:
> C
> 
> attached base packages:
> [1] "stats" "graphics"  "grDevices" "utils" "datasets"  "methods"
> [7] "base"
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lisp-like primitives in R

2007-09-06 Thread Duncan Murdoch
On 06/09/2007 7:36 PM, Roland Rau wrote:
> François Pinard wrote:
>> I wonder what happened, for R to hide the underlying Scheme so fully, at 
>> least at the level of the surface language (despite there are hints).  
> 
> As far as I understood, the original version of Ihaka/Gentleman was 
> written in Scheme. But even if you look at the source version of R 0.49 
> (the oldest I can find), the source files are written in C. In addition, 
> in their article published in "Journal of Computational and Graphical 
> Statistics" in 1996, Ihaka and Gentleman write on page 307: "To further 
> foster portability, we chose to write R in ANSI C"
> 
> Hope this clarifies the situation a bit. If we are lucky and one of the 
> original authors reads this thread they might explain the situation 
> further and better (and probably correct me).

You could also look at Ross Ihaka's paper that is online here:

http://cran.r-project.org/doc/html/interface98-paper/paper.html

R was written in C, with the intention that it be Scheme-like.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] computing distance in miles or km between 2 street addre

2007-09-06 Thread Duncan Murdoch
On 06/09/2007 6:17 PM, (Ted Harding) wrote:
> On 06-Sep-07 18:42:32, Philip James Smith wrote:
>> Hi R-ers:
>>
>> I need to compute the distance between 2 street addresses in
>> either km or miles. I do not care if the distance is a "shortest
>> driving route" or if it is "as the crow flies."
>>
>> Does anybody know how to do this? Can it be done in R? I have
>> thousands of addresses, so I think that Mapquest is out of the
>> question!
>>
>> Please rely to: [EMAIL PROTECTED]
>>
>> Thank you!
>> Phil Smith
> 
> That's a somewhat ill-posed question! You will for a start
> need a database of some kind, either of geographical locations
> (coordinates) of street addresses, or of the metric of the
> road network with capability to identify the street addresses
> in the database.
> 
> If it's just "as the crow flies", then it can be straightforwardly
> computed in R, either by Pythogoras (when they are not too far
> apart) or using a function which takes account of the shape of
> the Earth,
> 
> There are many R packages which have to do with mapping data.
> Search for "map" through the list of R packages at
> 
> http://finzi.psych.upenn.edu/R/library/maptools/html/00Index.html
> 
> -- maptools in particular. Also look at (for instance) aspace.
> 
> For "shortest driving route" then you need to find the shortest
> distance through a network. You may find some hints in the
> package optim -- but there must be some R experts out there
> on this sort of thing!
> 
> However, the primary need is for the database which gives
> the distance information in one form or another. What were
> you proposing to use for this? As far as I know, R has no
> database relevant to street addresses!

But if the addresses are in the US and include zip codes, a database is 
available online for free, here:

http://www.aggdata.com/files/zip_codes.zip

This includes latitude and longitude.  Zip codes cover a fairly large 
area so this won't give very accurate information, but it's easy to get.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] For loop with if else statement

2007-09-04 Thread Duncan Murdoch
On 9/4/2007 9:59 AM, Hans Ole Ørka wrote:
> Hi,
> I try to make a simple for loop with a if else statement (First example - 
> Below) and extend it to a more complex loop (Second example). However, my 
> results
> 
> #First example:
> x=c(1,2)
> t=for(i in 1:length(x)){
> if (x==1){a=x+1}else
> if (x==2){a=x}
> }
> 
> Returned from R:
> Warning messages:
> 1: the condition has length > 1 and only the first element will be used in: 
> if (x == 1) {
> 2: the condition has length > 1 and only the first element will be used in: 
> if (x == 1) {
>> t
> [1] 2 3
> 
> However, the result i had liked to get was t=c(2,2) i.e. using the first 
> function (a=x+1) for x[1] and (a=x) for x[2]. I can remove the Warnings by 
> making: if (x[i]==1) etc. but this do not make the results any better.

x is a vector of length 2.  Using a = x + 1 means that the entire vector 
a will be replaced by the entire vector x.  You need to index each entry 
each time you use it, i.e.

if (x[i] == 1) a[i] <- x[i] + 1
else if (x[i] ==2]) a[i] <- x[i]

or more simply, throw away the loop, and use the ifelse function:

a <- ifelse( x == 1, x + 1,
ifelse( x == 2,  x,
  NA) )

(where I've used NA for the case where x is neither 1 nor 2.)

Duncan Murdoch

> 
> #Second example:
> x=c(1,2)
> t<-for(i in 1:length(x)){
> if (x==1){
> a=x
> b=x-1}else
> if (x==2){
> a=x+1
> b=x}
> b<-list(a=a,b=b)
> }
> 
> Returned from R:
> Warning messages:
> 1: the condition has length > 1 and only the first element will be used in: 
> if (x == 1) {
> 2: the condition has length > 1 and only the first element will be used in: 
> if (x == 1) {
>> t
> $a
> [1] 1 2
> 
> $b
> [1] 0 1
> 
> The result i like to get are $a =c(1,3) and $b=c(0,2)
> 
> Probably there are couple of things that I do wrong and I appreciate all help!
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave rendering of simple character

2007-08-31 Thread Duncan Murdoch
Deepayan Sarkar wrote:
> On 8/31/07, Ken Knoblauch <[EMAIL PROTECTED]> wrote:
>   
>> Hi,
>>
>> When I compile the construction
>>
>> \begin{Scode}{eval=FALSE}
>> ?HSP
>> \end{Scode}
>>
>> with Sweave and latex, it outputs in the pdf as,
>>
>>  > `?` (HSP)
>>
>> which is not incorrect but a bit more formal than I wanted
>> for demonstrating the use of the help shortcut.
>> I would like the output to look like,
>>
>> 
>>> ?HSP
>>>   
>> but I can't seem to make this work.
>> 
>
> I'm not familiar with the Scode environment, but
>
>
> <>=
> ?HSP
> @
>
>
> does what you want.
>   
Like Deepayan, I also use <<>>= notation, but this probably works 
anywhere:  put keep.source=TRUE in your \SweaveOpts{} at the start of 
the file. 

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bugreport on integration of Sweave and latex beamer

2007-08-31 Thread Duncan Murdoch
Ajay Shah wrote:
> I think I have isolated a problem with integration between Sweave and beamer.
>   

Sweave makes a lot of use of verbatim environments, and beamer doesn't 
like those.  You need to declare that a slide contains verbatim or you 
get errors like that.

I'm sure there are other ways to do this, but one that works is to use

\begin{frame}[containsverbatim]

at the start of each slide.  This makes some other beamer features stop 
working, but I forget which.

Duncan Murdoch
> Could you please see the file:
>   http://www.mayin.org/ajayshah/tmp/bugdemo.Rnw
>
> Unfortunately, it uses some of my internal libraries, so you can't run
> it. When I put it through Sweave, I get:
>
>   http://www.mayin.org/ajayshah/tmp/bugdemo.tex
>
> which is, of course, a generic latex file which you can read and run.
>
> When I try to use pdflatex, I get the error:
>
> ...
> ...
> ...
> (/sw/share/texmf-dist/tex/latex/ae/t1aett.fd)
> Runaway argument?
>   
>> prices <- cbind(mydb("macro", "nifty", freq = "w"),
>> 
> mydb("firm.pric\ETC.
> ! Paragraph ended before [EMAIL PROTECTED] was complete.
>  
>\par 
> l.60 \end{frame}
> 
> ? 
>
> I transplanted the R code from bugdemo.Rnw into an ordinary latex
> article context, and everything works fine. Hence, I'm sure it's
> something to do with the integration between Sweave and beamer. Are
> there some catches that I ought to know about?
>
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Excel

2007-08-30 Thread Duncan Murdoch
On 30/08/2007 5:27 PM, Rolf Turner wrote:
> On 31/08/2007, at 9:10 AM, Antony Unwin wrote:
> 
>> Erich's more important point
>> is that you need to speak the language of the people you cooperate
>> with and often that language includes Excel.
> 
> So if the people you have to deal with are into astrology you should  
> learn astrology?

I don't think astrologers have much use for data, but if some did and 
wanted to hire me to analyze it, I think understanding their point of 
view would help.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Behaviour of very large numbers

2007-08-30 Thread Duncan Murdoch
On 8/30/2007 12:11 PM, Martin Becker wrote:
> willem vervoort wrote:
>> Dear all,
>> I am struggling to understand this.
>>
>> What happens when you raise a negative value to a power and the result
>> is a very large number?
>>
>>  B
>> [1] 47.73092
>>
>>   
>>> -51^B
>>> 
>> [1] -3.190824e+81
>>
>> # seems fine
>>   
> 
> Well, this seems not to be what you intended to do, you didn't raise a 
> negative value to a power, but you got the negative of a positive number 
> raised to that power (operator precedence, -51^B is the same as -(51^B) 
> and not the same as (-51)^B...).
> 
> If you really want to raise a negative value to a fractional power, you 
> may want to tell R to use complex numbers:
> 
> B <- 47.73092
> x <- complex(real=seq(-51,-49,length=10))
> 
> x^B
> 
>  [1] 2.117003e+81-2.387323e+81i 1.718701e+81-1.938163e+81i
>  [3] 1.394063e+81-1.572071e+81i 1.129702e+81-1.273954e+81i
>  [5] 9.146212e+80-1.031409e+81i 7.397943e+80-8.342587e+80i
>  [7] 5.978186e+80-6.741541e+80i 4.826284e+80-5.442553e+80i
>  [9] 3.892581e+80-4.389625e+80i 3.136461e+80-3.536955e+80i

But watch out if you do this, because of the arbitrary choice of a root. 
  You get oddities like this:

 > x <- complex(real = -1)
 > x
[1] -1+0i
 > 1/x
[1] -1+0i
 > x^(1/3)
[1] 0.5+0.8660254i
 > (1/x)^(1/3)
[1] 0.5-0.8660254i

i.e. even though x and 1/x are equal, the 1/3 powers of them are not.

Duncan Murdoch

P.S. I'm tempted to say, "But don't worry about it, the difference is 
only imaginary", but I'll refrain.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Excel (off-topic, sort of)

2007-08-30 Thread Duncan Murdoch
On 8/30/2007 10:43 AM, Thomas Lumley wrote:
> On Wed, 29 Aug 2007, Alberto Monteiro wrote:
>>>
>> Do you know what's in my wish list?
>>
>> I wish spreadsheets and computer languages had gone one
>> step further.
>>
>> I mean, it's nice to define Cell X to be "equal" to
>> Cell Y + 10, and then when we change Cell Y, magically we
>> see Cell X change.
>>
>> But why can't it be the reverse? Why can't I change Cell X
>> _and see the change in Cell Y_?
>>
> 
> Well, most statistical calculations are data-reducing, ie, many-to-one.
> 
> I don't think you are likely to find a language where you can change the 
> confidence limits for the sample mean and have the data change in 
> response.

But just think how much money you could make as a consultant if you 
could change the p-value from 0.08 to 0.01.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Behaviour of very large numbers

2007-08-30 Thread Duncan Murdoch
On 8/30/2007 11:08 AM, willem vervoort wrote:
> Dear all,
> I am struggling to understand this.
> 
> What happens when you raise a negative value to a power and the result
> is a very large number?
> 
>  B
> [1] 47.73092
> 
>> -51^B
> [1] -3.190824e+81

You should be using parentheses.  You evaluated -(51^B), not (-51)^B. 
The latter gives NaN.
> 
> # seems fine
> # now this:
>> x <- seq(-51,-49,length=100)
> 
>> x^B
>   [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 
> 
>> is.numeric(x^B)
> [1] TRUE
>> is.real(x^B)
> [1] TRUE
>> is.infinite(x^B)
>   [1] FALSE FALSE FALSE FALSE FALSE
> 
> I am lost, I checked the R mailing help, but could not find anything
> directly. I loaded package Brobdingnag and tried:
> as.brob(x^B)
>   [1] NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN) NAexp(NaN)
>> as.brob(x)^B
>   [1] NAexp(187.67) NAexp(187.65) NAexp(187.63) NAexp(187.61)
> 
> I guess I must be misunderstanding something fundamental.

Two things:  operator precedence (the ^ has higher precedence than the 
unary minus), and the mathematical definition of raising something to a 
fractional power.  The approach R takes to the latter is to define x^B 
to be exp(B * ln(x)), and ln(x) is undefined for negative x.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Excel

2007-08-30 Thread Duncan Murdoch
On 8/28/2007 3:16 AM, J Dougherty wrote:
> On Monday 27 August 2007 22:21, David Scott wrote:
>> On Tue, 28 Aug 2007, Robert A LaBudde wrote:
>> > If you format the column as "Text", you won't have this problem. By
>> > leaving the cells as "General", you leave it up to Excel to guess at
>> > the correct interpretation.
>>
>> Not true actually. I had converted the column to Text because I saw the
>> interpretation as a date in the .xls file. I saved the .csv file *after*
>> the column had been converted to Text. Looking at the .csv file in a text
>> editor, the entry is correct.
>>
>> I have just rechecked this.
>>
>> On reopening the .csv using Excel, the entry AUG2699 had been interpreted
>> as a date, and was showing as Aug-99. Most bizarre is that the NHI value
>> of AUG1838 has *not* been interpreted as a date.
>>
> Actually, in Excel 2000, he's right.  What you have to is be sure of is that 
> the "'" that denotes a text entry precedes EVERY entry that can be confused 
> with a date.  Selecting the entire column and setting the format to "text" 
> *before* data is entered does this.  It will also create an appropriate *.csv 
> file.  Excel is notable too because it will automatically convert "date-like" 
> entries as you type.  In a column of IDs or similar critical data, that 
> behaviour is really bad.  I have never tried the MS site, but I haven't been 
> able to find any entry about how to turn that particular automatic behaviour 
> off. 
> 
> However, while I have not experimented extensively, as far as I have 
> experimented, OpenOffice spreadsheet does not behave this way.

I don't use Excel, but in OpenOffice 2.2.1 the ' is lost when a file is 
saved as .csv and reloaded.  So if I take care and enter

'November 15

in a cell, then save it, OO will change it to 11/15/2007 when I reload. 
  I can override this change by manually changing "Standard" format to 
"Text" *every time* I load the file.  There's a help index entry "date 
formats;avoiding conversion to", but it offers no more help than "add an 
apostrophe at the beginning of the entry".

This is brain-dead behaviour.

Duncan Murdoch


> 
> JWDougherty
> 
> PS, I quit using Excel for most important work after it returned a negative 
> variance on some data I was collecting descriptive statistics on.
> 
> JWD
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Excel

2007-08-29 Thread Duncan Murdoch
[EMAIL PROTECTED] wrote:
> ...
>   

> Here are a few additional comments related to the representation issue in 
> .csv files:
> What is said about the .csv files with respect to rounding also holds for the 
> windows clipboard but not for the office clipboard. If you format data in an 
> excel range, select this range and paste it on a different worksheet (within 
> MS Office) the original representation is kept. That is, you can undo the 
> formating in the new copy. However, if you read the data into R using the 
> clipboard as a data source, only the formated version is transfered. I played 
> a bit with options and it really seems a clipboard implementation issue (a 
> job for Microsoft). Any lobbying wit MS to permit a better access to the 
> office clipboard would be useful in this context.

I did write some code to give access to special formats in the Windows 
clipboard.  If you can figure out what's there you should have access to 
it from R using getClipboardFormats and readClipboard. I think the only 
lobbying that would be needed would be to reveal the format, and that 
may have already been done.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] oddity with method definition

2007-08-27 Thread Duncan Murdoch
On 27/08/2007 5:47 PM, Faheem Mitha wrote:
> Just wondered about this curious behaviour. I'm trying to learn about 
> classes. Basically setMethod works the first time, but does not seem to 
> work the second time.
>  Faheem.
> *
> setClass("foo", representation(x="numeric"))
> 
> bar <- function(object)
>{
>  return(0)
>}
> 
> bar.foo <- function(object)
>{
>  print([EMAIL PROTECTED])
>}
> setMethod("bar", "foo", bar.foo)

This changes the definition of bar:  now it becomes a generic function 
instead of a simple function.

> 
> bar(f)
> 
> # bar(f) gives 1.

(You forgot the f = new("foo", x= 1) line, but that's somewhat obvious.)
> 
> bar <- function(object)
>{
>  return(0)
>}

Now bar is a regular function again.
> 
> bar.foo <- function(object)
>{
>  print([EMAIL PROTECTED])
>}
> setMethod("bar", "foo", bar.foo)

Now the generic would call that method, but you've wiped out the generic.

> 
> f = new("foo", x= 1)
> 
> bar(f)
> 
> # bar(f) gives 0, not 1.

The problem is that setting a method on a regular function automagically 
creates a generic for it, but redefining a function doesn't remove the 
generic.  It's still there, somewhere in R's insides, and if you could 
find it to call it your method would get called.  But you're calling the 
plain old bar() instead.

This behaviour makes more sense if you think about generics in other 
packages.  There's a generic called "show" in the methods package.  But 
you can define your own function called "show", and in your workspace, 
you'd want to call that, not the one from methods.

I'd recommend using setGeneric() to create a generic, rather than 
depending on the automatic creation, to avoid this kind of confusion.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] FAQ 7.x when 7 does not exist. Useability question

2007-08-27 Thread Duncan Murdoch
On 8/27/2007 8:52 AM, John Kane wrote:
> --- Duncan Murdoch <[EMAIL PROTECTED]> wrote:

>> I like the first, simple suggestion best; I'll put
>> it into R-devel.  
>> (With the slight change to use ul.menu instead
>> of just ul, because FAQ 2.7 includes a plain ul
>> list.)
>> 
>> Duncan Murdoch
> Thanks Deepayan and Duncan.  
> 
> It is not a make or break point in using R but it does
> seem to make the FAQ a bit more user-friendly.

I'm about to commit the change, but it's not perfect.  I've applied the 
change to the css used in all the manuals, not just the FAQ, so the HTML 
versions of the manuals now end up with numbered contents listings too. 
  However, appendices continue the chapter numbering, rather than 
switching to letters.  I think this is preferable to no numbering at 
all, but if others object to it, we can make this change for the FAQ only.

Another way to do this is what's used in the texinfo manual
http://www.gnu.org/software/texinfo/manual/texinfo/texinfo.html
but I find that ugly and inconsistent.  The contents listing gets the 
numbering and lettering right (but not well formatted), but within each 
chapter the menus are unnumbered.

The texinfo format is just a bit limited for this kind of thing.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How is "R CMD INSTALL --help" executed?

2007-08-26 Thread Duncan Murdoch
On 26/08/2007 3:55 PM, [EMAIL PROTECTED] wrote:
> Installation Configuration: Windows XP version 5.1 with Service Pack 2, 
> Rtools (bin, MnGW, perl), and HTML HelpWorkshop,  and R-2.5.1.
> Files Located: Scrips build, check and install are in C:\Program 
> Files\R\R-2.5.1\bin.
> Path Verified:  Windows path begins with  "c:\Rtools\bin; c:\Rtools\perl\bin; 
> c:\Rtools\MinGW\bin;" (without quotes).
> Documents Being Read: Writing R Extensions, and "The Windows toolset" in 
> R-admin.
> 
> The Problem: The example in R Help package.skeleton was created and the 
> produced files were edited.  In what window, at what prompt, or in what other 
> way is R CMD INSTALL --help  entered or executed? 

At a command prompt, i.e. in a "DOS window", or Cygwin, or some other 
shell, outside of R.

> What additional setup is required for the system to recognize this command?

What you list above should be sufficient.

Duncan Murdoch

> Found example "R CMD build --force --binary --auto-zip %1 pkgname" in 
> search.R-project.org .  What must be done so system can find package pkgname?
> 
> Bill Morphet
> ATK Launch Systems, RSRM Postfire Evaluation Eng
> 
> 
> 
> 
> Subject:
> Returned mail: User unknown
> From:
> [EMAIL PROTECTED] (Webmail Postmaster)
> Date:
> Sun, 26 Aug 2007 17:43:16 +
> To:
> [EMAIL PROTECTED]
> 
> To:
> [EMAIL PROTECTED]
> 
> 
> 
> 
> 
> Subject:
> How is "R CMD INSTALL --help" executed?
> From:
> [EMAIL PROTECTED]
> Date:
> Sun, 26 Aug 2007 17:43:15 +
> To:
> r-help_at_stat.math.ethz.ch
> 
> To:
> r-help_at_stat.math.ethz.ch
> BCC:
> [EMAIL PROTECTED]
> 
> 
> 
> 
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] FAQ 7.x when 7 does not exist. Useability question

2007-08-26 Thread Duncan Murdoch
Deepayan Sarkar wrote:
> On 8/23/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
>   
>> On 8/23/2007 11:28 AM, Prof Brian Ripley wrote:
>> 
>>> On Thu, 23 Aug 2007, John Kane wrote:
>>>
>>>   
>>>> The FAQ Section 7 is a very useful place for new users
>>>> to find out any number of R idiosycracies.  However
>>>> there is no numbering on the FAQ Table of Content or
>>>> on the Sections Tables of Contents.
>>>> 
>>> Hmm, doc/FAQ does have a numbered table of contents and numbered sections
>>> and doc/manual/R-FAQ.html does have numbered sections and my browser's
>>> search finds 7.10 straight away.
>>>   
>> I think the suggestion is to change the contents lists in HTML from 
>> lists to  lists.  Then one would see
>>
>> 1. Introduction
>> 2. R Basics
>> 3. R and S
>> 4. R Web Interfaces
>> 5. R Add-On Packages
>> 6. R and Emacs
>> 7. R Miscellanea
>> 8. R Programming
>> 9. R Bugs
>>10. Acknowledgments
>>
>> instead of
>>
>>  * Introduction
>>  * R Basics
>>  * R and S
>>  * R Web Interfaces
>>  * R Add-On Packages
>>  * R and Emacs
>>  * R Miscellanea
>>  * R Programming
>>  * R Bugs
>>  * Acknowledgments
>>
>> in a browser, and I agree that would be preferable (assuming the
>> numbering is consistent with what we get in the other formats).
>> However, I don't see how to tell makeinfo --html to do this.  Adding
>> --number-sections isn't enough.
>> 
>
> A simple CSS hack is to have
>
> ul{
> list-style-type: decimal;
> }
>
> in the style. The result can be seen in
>
> http://dsarkar.fhcrc.org/R/RFAQ-1.png
>
> A more sophisticated hack is to have something like
>
> ---
> body{
> counter-reset: chapter;
> counter-reset: section;
> }
> h2.chapter {
> counter-increment: chapter;
> counter-reset: section;
> }
>
> ul {
> list-style-type: none;
> }
>
> li:before {
> counter-increment: section;
> content: counter(chapter) "." counter(section) " " ;
> }
> -
>
> which results in
>
> http://dsarkar.fhcrc.org/R/RFAQ-2.png
>
> The only problem here is that there is no way to distinguish between
> the chapter listing and the section listings (both are  class="menu">). If that could be made to have a different class, the
> chapter listing could be improved.

I like the first, simple suggestion best; I'll put it into R-devel.  
(With the slight change to use ul.menu instead
of just ul, because FAQ 2.7 includes a plain ul list.)

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error message!

2007-08-26 Thread Duncan Murdoch
Usman Shehu wrote:
> It is not. I tried using a number of mirrors, eg Germany, Uk(Bristol), 
> Netherlands, etc.
>
>   
In that case, you'll have to debug it.  Run traceback after the error.  
.readRDS(pfile) is called in several different places; you'll need to 
find out where it's happening, and why it's failing. The traceback() 
will tell you where; you can use debug() on that function to single step 
through until you get to this line, and see what pfile is set to.

BTW, please keep the discussion in R-help; someone else may have better 
contributions than me.

Duncan
>
> - Original Message 
> From: Duncan Murdoch <[EMAIL PROTECTED]>
> To: Usman Shehu <[EMAIL PROTECTED]>
> Cc: r-help@stat.math.ethz.ch
> Sent: Sunday, 26 August, 2007 12:02:13 PM
> Subject: Re: [R] error message!
>
>
> On 26/08/2007 6:13 AM, Usman Shehu wrote:
>   
>> Dear R-users,
>> Can some one help me out. I tried installing some packages in R_2.5.1  but I 
>> get an error message as shown below. This is unusual since I have been 
>> installing and updatings packages in the same version of R.
>>
>> 
>>> chooseCRANmirror()
>>> update.packages(ask='graphics')
>>>   
>> Error in .readRDS(pfile) : unknown input format
>> or
>> 
>>> utils:::menuInstallPkgs()
>>>   
>> Error in .readRDS(pfile) : unknown input format
>> 
>
> I'd guess it's a problem with the mirror.  Which one did you choose?  Do 
> you get the same error if you choose a different one?
>
> Duncan Murdoch
>
>
>   ___
> Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
> now.
> http://uk.answers.yahoo.com/ 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to provide argument when opening RGui from an external application

2007-08-26 Thread Duncan Murdoch
On 26/08/2007 7:14 AM, Sébastien wrote:
> Thanks for your reply.
> When you say "look into Rscript.exe", do you have a specific document in 
> mind ? I tried to google it but could not find much... I forgot to 
> mention in my first email that I am working under the Windows XP 
> environment.

You could try ?Rscript within R, or Rscript --help from the command line 
(assuming you have R's bin directory on your path.

Duncan Murdoch

> 
> Prof Brian Ripley a écrit :
>> Look into Rscript.exe (on Windows), which is a flexible way to run 
>> scripts.  Neither using a GUI nor using source() are recommended.
>>
>> On Fri, 24 Aug 2007, Sébastien wrote:
>>
>>> Dear R-users,
>>>
>>> I have written a small application (in visual basic) that automatically
>>> generate some R scripts. I would like to execute these scripts when my
>>> application is being closed.
>>> My problem is that I don't know how to pass the
>>> 'source(c:/.../myscript.r)' instruction when I programmatically start
>>> RGui. Tinn-R is capable of doing such things, so I guess there must be a
>>> way to pass arguments to RGui.
>>>
>>> Any advice or link to relevant references would be greatly appreciated.
>>>
>>> Sebastien
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error message!

2007-08-26 Thread Duncan Murdoch
On 26/08/2007 6:13 AM, Usman Shehu wrote:
> Dear R-users,
> Can some one help me out. I tried installing some packages in R_2.5.1  but I 
> get an error message as shown below. This is unusual since I have been 
> installing and updatings packages in the same version of R.
> 
>> chooseCRANmirror()
>> update.packages(ask='graphics')
> Error in .readRDS(pfile) : unknown input format
> or
>> utils:::menuInstallPkgs()
> Error in .readRDS(pfile) : unknown input format

I'd guess it's a problem with the mirror.  Which one did you choose?  Do 
you get the same error if you choose a different one?

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 11:14 AM, Dirk Eddelbuettel wrote:
> On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
>> On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
>>> On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
>>>> On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
>>>> > Hi,
>>>> > > It is possible to use a shell command inside a R script?
>>>> > > I'm write a R script and I like to put somes shell commands inside to 
>>>> R. > Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
>>>> The details and available functions depend on the platform, but you want 
>>>> to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
>>>> Windows; on Unix-alikes, you probably won't have the latter two.)
>>> Don't forget pipes. R's ability to consistently work on connections that 
>>> may be local
>>> files, remotes files, program output, ... is a true treasure (and
>>> thanks and credits to, I believe, Brian Ripley to make it so).
>>> Eg you can do this   OD <- read.table(pipe("links -dump 
>>> http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'"), 
>>> header=FALSE, col.names=c("file", "date"))
>>> to get files and dates of files on CRAN.   As I recall, this also works on 
>>> that other operating system, provided
>>> you do all the legwork of installing other tools, setting PATHs etc
>>> to provide what works out of the box on the supposedly unfriendlier OS.
>>
>> The pipe command you list doesn't work in Windows.  I'd guess this is 
>> because the pipe syntax "|" within the command is unsupported:  it tries to 
>> execute "links", with the rest of the line passed as arguments.  But I 
>> haven't traced through to check on this.
> 
> Hm, wishful thinking must have gotten the better of me then. Sorry for
> spreading misinformation about the capabilities of that other OS.

Actually, the OS is fine, it's R that's not.  I'll fix it for 2.6.0.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 1:05 PM, Gabor Grothendieck wrote:
> On 8/24/07, Dirk Eddelbuettel <[EMAIL PROTECTED]> wrote:
>> On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
>> > On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
>> >> On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
>> >>> On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
>> >>> > Hi,
>> >>> > > It is possible to use a shell command inside a R script?
>> >>> > > I'm write a R script and I like to put somes shell commands inside to
>> >>> R. > Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
>> >>> The details and available functions depend on the platform, but you want
>> >>> to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in
>> >>> Windows; on Unix-alikes, you probably won't have the latter two.)
>> >> Don't forget pipes. R's ability to consistently work on connections that
>> >> may be local
>> >> files, remotes files, program output, ... is a true treasure (and
>> >> thanks and credits to, I believe, Brian Ripley to make it so).
>> >> Eg you can do this   OD <- read.table(pipe("links -dump
>> >> http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'"),
>> >> header=FALSE, col.names=c("file", "date"))
>> >> to get files and dates of files on CRAN.   As I recall, this also works on
>> >> that other operating system, provided
>> >> you do all the legwork of installing other tools, setting PATHs etc
>> >> to provide what works out of the box on the supposedly unfriendlier OS.
>> >
>> > The pipe command you list doesn't work in Windows.  I'd guess this is
>> > because the pipe syntax "|" within the command is unsupported:  it tries to
>> > execute "links", with the rest of the line passed as arguments.  But I
>> > haven't traced through to check on this.
>>
>> Hm, wishful thinking must have gotten the better of me then. Sorry for
>> spreading misinformation about the capabilities of that other OS.
> 
> This works for me on Windows:
> 
>> tab <- read.table(pipe("lynx --nolist --dump 
>> http://cran.r-project.org/src/contrib/ | findstr tar.gz"), as.is = TRUE)

Which R version is that?  It doesn't work for me in Rgui, though it does 
  in Rterm, both R-devel versions.

Duncan Murdoch

>> head(tab[3:5])
>V3  V4V5
> 1 ADaCGH_1.3-1.tar.gz 14-May-2007 12:04
> 2  AIS_1.0.tar.gz 31-Jul-2007 16:38
> 3 AMORE_0.2-10.tar.gz 11-Apr-2007 10:17
> 4   ARES_1.2-2.tar.gz 19-Mar-2007 20:53
> 5 AcceptanceSampling_0.1-1.tar.gz 07-Jul-2007 20:46
> 6   AdaptFit_0.2-1.tar.gz 04-Aug-2007 09:51

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
> On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
>> On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
>> > Hi,
>> > 
>> > It is possible to use a shell command inside a R script?
>> > 
>> > I'm write a R script and I like to put somes shell commands inside to R. 
>> > Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
>> 
>> The details and available functions depend on the platform, but you want 
>> to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
>> Windows; on Unix-alikes, you probably won't have the latter two.)
> 
> Don't forget pipes. 
> 
> R's ability to consistently work on connections that may be local
> files, remotes files, program output, ... is a true treasure (and
> thanks and credits to, I believe, Brian Ripley to make it so).
> 
> Eg you can do this 
> 
>   OD <- read.table(pipe("links -dump http://cran.r-project.org/src/contrib/ | 
> awk '/tar.gz/ {print $3, $4}'"), header=FALSE, col.names=c("file", "date"))
> 
> to get files and dates of files on CRAN.   
> 
> As I recall, this also works on that other operating system, provided
> you do all the legwork of installing other tools, setting PATHs etc
> to provide what works out of the box on the supposedly unfriendlier OS.

The pipe command you list doesn't work in Windows.  I'd guess this is 
because the pipe syntax "|" within the command is unsupported:  it tries 
to execute "links", with the rest of the line passed as arguments.  But 
I haven't traced through to check on this.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 8:05 AM, Alberto Monteiro wrote:
> Ronaldo Reis Junior wrote:
>> 
>> It is possible to use a shell command inside a R script?
>> 
>> I'm write a R script and I like to put somes shell commands inside 
>> to R. Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
>> 
>> It is possible? How?
>> 
> ?system
> 
> BTW, I found that using things directly in R is _much_
> slower than creating a batch file and then running it.
> 
> For example, I had a directory with misnamed mp3 files,
> and I wanted to use R to rename and copy them
> to another directory. I tried to use file.copy, but it 
> took too much time. Writing a batch file and then running
> it was much faster.

Since you say "batch file" I assume you're on Windows.  If that's the 
case, then file.rename() can rename and move a file to a new directory, 
as long as it's on the same drive.  That should be as quick as a batch file.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
> Hi,
> 
> It is possible to use a shell command inside a R script?
> 
> I'm write a R script and I like to put somes shell commands inside to R. 
> Somethink like: convert fig01.png fig01.xpm or sed ..., etc.

The details and available functions depend on the platform, but you want 
to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
Windows; on Unix-alikes, you probably won't have the latter two.)

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] FAQ 7.x when 7 does not exist. Useability question

2007-08-23 Thread Duncan Murdoch
On 8/23/2007 11:28 AM, Prof Brian Ripley wrote:
> On Thu, 23 Aug 2007, John Kane wrote:
> 
>> The FAQ Section 7 is a very useful place for new users
>> to find out any number of R idiosycracies.  However
>> there is no numbering on the FAQ Table of Content or
>> on the Sections Tables of Contents.
> 
> Hmm, doc/FAQ does have a numbered table of contents and numbered sections 
> and doc/manual/R-FAQ.html does have numbered sections and my browser's 
> search finds 7.10 straight away.

I think the suggestion is to change the contents lists in HTML from  
lists to  lists.  Then one would see

1. Introduction
2. R Basics
3. R and S
4. R Web Interfaces
5. R Add-On Packages
6. R and Emacs
7. R Miscellanea
8. R Programming
9. R Bugs
   10. Acknowledgments

instead of

 * Introduction
 * R Basics
 * R and S
 * R Web Interfaces
 * R Add-On Packages
 * R and Emacs
 * R Miscellanea
 * R Programming
 * R Bugs
 * Acknowledgments

in a browser, and I agree that would be preferable (assuming the 
numbering is consistent with what we get in the other formats). 
However, I don't see how to tell makeinfo --html to do this.  Adding 
--number-sections isn't enough.

Duncan Murdoch

> 
> 
>> An R-help list reply of "Read FAQ 7.10" in response to
>> a question about converting a factor to numeric is  a
>> bit cryptic. The only time 7.10 appears is after the
>> searcher has found the entry.
> 
> It would help if you told us what you are searching that did not contain 
> '7.10'.
> 
>> Would it be a good idea to actually number the entries
>> for the FAQ Table of Contents and the Table of
>> Contents for the Sections?
> 
> I think we do.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] integrate

2007-08-22 Thread Duncan Murdoch
On 8/22/2007 3:54 PM, Santanu Pramanik wrote:
> Hi,
> I am trying to integrate a function which is approximately constant
> over the range of the integration. The function is as follows:

That's not a function of the input mu.  It includes a random component:

 > my.fcn(10)
[1] 0.9786558
 > my.fcn(10)
[1] 1.022467

You can't expect integrate() to return a sensible answer if you don't 
give it a function that returns consistent results.

Duncan Murdoch

>  
>> my.fcn = function(mu){
> + m = 1000
> + z = 0
> + z.mse = 0
> + for(i in 1:m){
> + z[i] = rnorm(1, mu, 1)
> + z.mse = z.mse + (z[i] - mu)^2
> + }
> + return(z.mse/m)
> + }
> 
>> my.fcn(-10)
> [1] 1.021711
>> my.fcn(10)
> [1] 0.9995235
>> my.fcn(-5)
> [1] 1.012727
>> my.fcn(5)
> [1] 1.033595
>> my.fcn(0)
> [1] 1.106282
>> 
> The function takes the value (approx) 1 over the range of mu. So the
> integration result should be close to 20 if we integrate over (-10, 10).
> But R gives:
> 
>> integrate(my.fcn, -10, 10)
> 685.4941 with absolute error < 7.6e-12
> 
>> integrate(Vectorize(my.fcn), -10, 10)  # this code never terminate
>  
> I have seen in the "?integrate" page it is clearly written:
>  
> If the function is approximately constant (in particular, zero) over
> nearly all its range it is possible that the result and error estimate
> may be seriously wrong. 
>  
> But this doesn't help in solving the problem.
> Thanks,
> Santanu
> 
> 
>  
> JPSM, 1218J Lefrak Hall
> University of Maryland, College Park
> Phone: 301-314-9916
>  
>  
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Synchronzing workspaces

2007-08-22 Thread Duncan Murdoch
On 8/22/2007 9:20 AM, Eric Turkheimer wrote:
> How do people go about synchronizing multiple workspaces on different
> workstations?  I tend to wind up with projects spread around the various
> machines I work on.  I find that placing the directories on a server and
> reading them remotely tends to slow things down.

I use Subversion.  It works best with text, but can handle binary files too.

So the idea would be to write scripts that either generate or load the 
data I want to work on, and source those at the beginning of a session. 
  I always try to start with a clean workspace.

Separate the code that does complex calculations into functions (and 
consider organizing it into a package, if it's big enough); put those 
functions in separate files from the scripts that run them on particular 
examples.  This way you can run source("fns.R") to update the function 
definitions without re-doing all the simulations in your project.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Processing Sweave documents without Sweave

2007-08-22 Thread Duncan Murdoch
On 8/22/2007 6:40 AM, Renaud Lancelot wrote:
> Sweave produces a TeX file which can be exchanged like any other such
> file, providing that you give the possible graphic files (and bib,
> etc.) called from the TeX code.

Yes, and since Sweave doesn't touch the formatting of the TeX code, it's 
not hard to recognize and merge changes to the .tex file back into the 
Rnw file.

Duncan Murdoch
> 
> Best,
> 
> Renaud
> 
> 2007/8/22, Werner Wernersen <[EMAIL PROTECTED]>:
>> Hi,
>>
>> I am very intrigued by the idea of integrating
>> statistical analysis directly with a paper as Sweave
>> does it. But as I am collaborating with several people
>> and they won't have set up R and also they're very
>> unlikely interested in learning it, I am concerned
>> about how such an Latex/Sweave document will work on
>> their side.
>>
>> Can they Latex-compile the document without having R /
>> Sweave installed and still see the numbers and figures
>> I produced by an earlier run of Latex / R / Sweave? Is
>> there any option or so planned for this case? Or how
>> are you coping with this problem otherwise?
>>
>> Many thanks,
>>   Werner
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Formatting Sweave in R-News

2007-08-22 Thread Duncan Murdoch
On 8/22/2007 3:20 AM, Gregor Gorjanc wrote:
> Arjun Ravi Narayan  arjunnarayan.com> writes:
>> I am editing a document for submission to the R-news newsletter, and
>> in my article my Sweave code inserts a dynamically generated PDF
>> report that my R program generates.
>> 
> 
> Slightly off Arjuns topic is a problem with Schunk, Sinput and Soutput 
> environments. They just use to much inline space. I have tweade this
> problem with sed (see bellow for Makefile content), but wonder if there 
> is a better solution.

You can change the spacing by redefining those environments.  I use this:

% This removes the extra spacing after code and output chunks in Sweave,
% but keeps the spacing around the whole block.

\fvset{listparameters={\setlength{\topsep}{0pt}}}
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}


> Thanks, Gregor
> 
> default: Sweave fixTex
>   texi2pdf --clean wrapper.tex && evince wrapper.pdf
> 
> Sweave: # Sweave myPaper.Rnw
>   R CMD Sweave myPaper.Rnw
> 
> fixTex: Sweave # Change all S* environments to smallverbatim
>   @cat myPaper.tex | sed -e '/\\begin{Sinput}/d' \
>  -e '/\\end{Sinput}/d' \
>  -e '/\\begin{Soutput}/d' \
>  -e '/\\end{Soutput}/d' \
>  -e 's/\\begin{Schunk}/\\begin{smallverbatim}/g' \
>  -e 's/\\end{Schunk}/\\end{smallverbatim}/g' \
>   > myPaper2.tex
>   @mv -f myPaper2.tex myPaper.tex
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] C code generators

2007-08-22 Thread Duncan Murdoch
On 8/21/2007 10:20 PM, [EMAIL PROTECTED] wrote:
> Dear R-helpers
> 
> Are there any established R packages that include a C code generator -- 
> that generates new C language files and compiles them?

Oleg Sklyar's inline package does that.  It takes input in the form of a 
fragment of C (or C++, Fortran, etc.), completes the source code, 
compiles it, loads it, and creates an R function to call it.  See the 
?cfunction man page for examples.

I wouldn't recommend this for extensive use:  you're better off putting 
your own code in a package instead.  But it's good for quick tests, or 
writing the first version of the code that goes in the package.

> To be precise what I'm looking for is a process that takes text input in
> some format (it might be pseudocode, fragments of C code, etc) and creates
> a valid C language source file that can be compiled by R CMD COMPILE.
> Ideally the procedure should also cause the C code to be compiled and
> dynamically loaded.
> 
> To give a trivial example, suppose I want to be able to perform image
> filtering operations on matrices. All filters have the same structure:
> each position [i,j] in the matrix is visited in a double loop; a
> calculation (depending on the filter) is performed using the value at
> [i,j] and also the values at neighbouring positions [i+1,j] , [i+1,j+1]
> etc; the result is written to the output matrix at the position [i,j]. The
> C code for the loop is always the same; only a few lines of code that
> perform the filter calculation will change. I would like a procedure that
> accepts a text file containing just a few lines of C code or pseudocode,
> and inserts these lines into the appropriate place in the loop, producing
> a valid C language routine which can then be compiled by R CMD COMPILE and
> dynamically loaded.

As a matter of fact, one of Oleg's examples is an image filter.

Duncan Murdoch

> 
> (Of course, it can get more complicated than just inserting a single text
> fragment!)
> 
> I once implemented such a feature in an image processing package, so I
> know it's not hard. Before dusting off this ancient code I would like to
> learn whether there's an R package or other open source program that
> already does it.
> 
> Any pointers would be welcome
> 
> thanks
> Adrian Baddeley
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how do i use the get function to obtain an element from a list...

2007-08-21 Thread Duncan Murdoch
On 8/21/2007 3:35 PM, Juan Manuel Barreneche wrote:
> my problem can be explained with the following example:
> 
> x <- 1:12
> y <- 13:24
> a <- data.frame(x = x, y = y)
> 
> ## if i write
> a$x
> ## it returns
> [1]  1  2  3  4  5  6  7  8  9 10 11 12
> 
> ## but the function get doesn't recognize a$x. Instead it produces the
> following error:
> get("a$x")
> Error in get(x, envir, mode, inherits) : variable "a$x" was not found

a$x is an expression, which you could evaluate, not a variable, which 
you could get.

> 
> i intend to do it inside a loop, using a new object (and hence, a new
> name) for each iteration (i.e., instead of a$x, it would be a$1, a$2,
> a$3, and so on, for a million times).
> 
> i would greatly appreciate it if someone could help me on this issue,

Why name things?  I'd use something like

for (i in 1:100) print(a[[i]])

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Variable c and function c

2007-08-21 Thread Duncan Murdoch
On 8/21/2007 11:07 AM, Vladimir Eremeev wrote:
> I have found the error in my script which was semi-automatically translated
> from the other person's MATLAB code.
> 
> The error is that c was assigned a value inside a function.
> That is the function body contained the following instructions
>   c<-nw*czr
>   d<-nw*cz
>   rFren<-0.5*(abs((cz-c)/(cz+c))^2+abs((d-czr)/(d+czr))^2)
>   firstguess<-c( 0,0,0,3,0.5,  0 , 0 ,  0.01)
> 
> I have already run this function and obtained the results, it was rather
> long process, therefore I don't want to rerun it.
> 
> I was not given any warnings. 
> How did the interpreter treat this? 
> Will the result change, if I change the variable from "c" to, say, "c." ?
> This variable is not used anywhere else in the function.

When looking for a function, R will ignore variables that are not 
functions.  So what you show above is not an error, though it can be 
confusing, so it's not a good idea.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Any parser generator / code assistance for R?

2007-08-20 Thread Duncan Murdoch
On 8/20/2007 1:27 PM, Ali - wrote:
>> A-> Hi,> A-> Is there any parser generator like www.antlr.org? Moreover, how 
>> does simple > A-> code assistance work currently in R? By 'simple code 
>> assistance' I meant > A-> things like:> > A-> Object$M --> 
>> Object$Method> > If you really meant a list with components> or an S4 object 
>> with slots,> such code completion works at least since R 2.5.1, because of> 
>> the recent 'rcompletion' extensions of Deepayan Sarkar,> and of course in 
>> ESS (Emacs Speaks Statistics),> and I think in several other 
>> GUI/Environments as well.> > But if you are thinking OOP as in Java or C++ 
>> (and I think you> *are* thinking along that way), then rather learn> that S 
>> (and hence R) do OOP in a function-centric rather than class-centric> way; 
>> something which seems to be quite hard to grasp for many> who have been 
>> brought up in Java-like schools> If you are still interested in R, look 
>> out for documents with> "S4" (or "formal methods and classes") and "R" in 
>> the title ;-)
> I am looking for an implemented parser generator of 'R', not only S4 classes 
> or OOP style. By 'R', I mean 'R', it's that simple.
>  
> I am not a big fan of the inconsistency in R grammer for the price of freedom 
> in bringing new inventions such as S4. 

What inconsistencies are you talking about?  There are plenty of 
semantic inconsistencies, but I can't think of any at the parser level. 
  In general the parser doesn't know anything about S3, S4, etc.

I understand this is a controversial subject and that many claim that in 
this way more options are brought to R. However, this makes R to look 
like a 'confused' language to me which is undecided between 
function-centric and object-oriented. We have the OOP package, the 
methods package and now the S4 classes which are very different to S3 
and my understanding is that the S3-based packages are not automatically 
upgradable to S4. What if in 7 years or so the authors decide to have a 
S5 class scheme which is very different to both S3 and S4?
>  
> In this way, it seems to me that there is no 'standard' in R. You may choose 
> a flavour for R like R-S4 or R-S3 or R-this or R-that, and then develop your 
> package based on that flavour. However, it looks like R-this and R-that 
> flavours are actually different languages sharing some syntax.


> Here is a good demonstration for this problem: can we have one 'universal' 
> parser for R?  Or do we need an R-this-parser and R-that-parser for each 
> flavour?

There's currently only one parser for R, generated from src/main/gram.y.

  It seems that Martin said yes to the second question.
>  
> Moreover, my question is still somehow un-answered: Is there any existing 
> ANTLR-based parser for R? I understand that in omegahat.org project, people 
> used ANTLR for RSJava, but i am not sure if that had anything to do with an 
> R-parser.

I doubt it.  The parser for R is written in yacc/bison, and since nobody 
has pointed to one based on ANTLR, it probably doesn't exist.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] library(fCalendar) timeDate("12.03.2005", format="%d.%m.%Y")

2007-08-20 Thread Duncan Murdoch
On 8/20/2007 9:26 AM, Ola Lindqvist wrote:
> Dear R users,
> I have problem with the library fCalendar.
> 
> I am not using the US standard format notations. It seems like it is not 
> possible to have different format than the US standards.
> Anyone how knows a way to go around this problem?
> 
> Here is the code I enter:
> myDate = "12.03.2005"
> timeDate(myDate, format = "%d.%m.%Y")
> 
> And I get following error message:
> Error in if (sum(lt$sec + lt$min + lt$hour) == 0) isoFormat = "%Y-%m-%d" :
> missing value where TRUE/FALSE needed
> 


You should address questions about contributed packages to the 
maintainer of the package, in this case Diethelm Wuertz and Rmetrics 
Core Team <[EMAIL PROTECTED]>.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] recommended combo of apps for new user?

2007-08-18 Thread Duncan Murdoch
Martin Brown wrote:
> [i sent this message earlier but apparently should have sent it plain
> text, as follows..]
>
> Hi there,
>
> I would like some advice, not so much about how to use R, but about
> software that I need to complement R.  I've rooted around in the FAQ's
> and done a few searches on this mailing list but haven't quite found
> the perspective I need.
>
> I am an experienced data analyst in my field (forest ecology and
> ecological monitoring) but new to R. I am a long time user of SPSS and
> have gotten pretty handy with it.  However, I am frustrated with SPSS
> for several reasons:  There's the cost (I'm a freelancer; I pay for my
> software myself);  the Windows dependence (I use Kubuntu as my usual
> OS now, and switching back and forth is a pain); the horrible
> inefficiency when I do certain types of file manipulations; and the
> inability to do the kind of publication-quality graphs I want... I've
> usually ended up using a commercial graphing program (another source
> of expense and limitation).
>
> I'd like to switch to using R on Kubuntu, for all those reasons.  In
> addition I think the mathematical formality that R encourages might be
> good for me.
>
> However, reviewing the FAQ's on the R project web site makes me
> realize that I've been using SPSS as three kinds of software really:
> a DBMS; a statistical analysis package; and a graphing package.  It
> looks like moving to R might involve learning three kinds of software,
> not just one.  I wonder:
>
> 1) What open-source DBMS works most seamlessly with R?  I have seen
> MySQL recommended but wonder if there are alternatives.  I sometimes
> need to handle big data files.  In fact a lot of my work involves
> exploratory and descriptive analyses of rather large and messy
> databases from ecological monitoring, rather than statistical tests
> per se.  In SPSS the data files I have been generating have dozens of
> columns and thousands of rows, often with value and variable labels
> helpful for documenting my work.
>   

I think you won't find much difference in the R interface between MySQL, 
PostgreSQL, or SQLite.  The choice should be made based on the qualities 
of the database (and I don't know enough about the differences to give a 
recommendaton.)
> 2) For the purpose of creating publication-quality graphs, do R users
> typically need to go outside of the R system? If so, what open-source
> programs would you all recommend?
>   
R is great for this, but you might need to go outside for some 
specialized stuff (e.g. medical imaging).

> 3) Any other software I need to learn that would make my work in R
> more productive? (for example, a code editor).

A lot of people are happy with ESS mode in Emacs.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] number precision

2007-08-18 Thread Duncan Murdoch
[EMAIL PROTECTED] wrote:
> Hi,
>
> I'm trying to find a way to determine how many digits a number has. I tried 
> using nchar(paste(number)), but unfortunately paste will reduce 8.00 to "8".
>   

I think your problem is that "the number of digits a number has" is not 
a property of the number (since the numbers 8.00 and 8 are the same 
number).  You need to keep track of the digits in some other way.  One 
possibility is to store two numbers:  the lowest possible value and the 
highest possible value.  Then 8.00 would be stored as (7.995,  8.005).  
It's then possible (but not easy) to propagate these ranges through 
transformations.

Duncan Murdoch
> Any thoughts?
> Pieter
>
> --
> This message was sent on behalf of [EMAIL PROTECTED] at openSubscriber.com
> http://www.opensubscriber.com/messages/r-help@stat.math.ethz.ch/topic.html
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] names not inherited in functions

2007-08-17 Thread Duncan Murdoch
On 8/17/2007 1:17 PM, david dav wrote:
> Dear R list,
> After a huge delay, I come back to this question. Using names of
> variables inside a function is a problem I run into quite often.
> Maybe this little example should help to get my point:
> Suppose I want to make a function "llabel" to get the labels of the
> variables from a data frame.
> If no label is defined, "llabel" should return the name of the variable.
> 
>   library(Hmisc)
>   v1 <- c(1,2)
>   v2 <- c(1,2)
>   v3 <- c(1,3)
>   tablo <- data.frame(v1,v2,v3)
>   rm(v1,v2,v3)
> 
>   label(tablo$v1) <- "var1"
>   attach(tablo)

I don't think attach() does what most people think it does. I'd 
recommend avoiding it. with() is better.  But this isn't your problem...

> 
> # This does the trick on one variable.
>   if (label(v1) !="") label(v1)   else names(data.frame(v1))
>   if (label(v2) !="") label(v2)   else names(data.frame(v2))

This isn't actually working.  "data.frame(v1)" creates a new data frame 
containing v1, so names(data.frame(v1)) is just a long-winded way to say 
"v1".  (This isn't true for every possible choice of v1, but it's true 
when v1 is a numeric vector.)

>   
> But if I call this statement in a "llabel" function,
> 
>   llabel <- function(var) {
>   if (label(var) !="" )
>   res <- label(var)
>   else res <- names(data.frame(var))
>   return (res) }

Use "else res <- deparse(substitute(var))" as the 4th line.  This says 
to return the expression that was passed to the function if the label() 
function returned a blank.

Duncan Murdoch
>   
> I just get "var"s instead of the names when no label is defined :
>   
> llabel(v1) # works
> llabel(v2) # gives "var" instead of "v2"
> 
> Thanks for your help.
> 
> David
> 
> 
> 2007/6/7, Uwe Ligges <[EMAIL PROTECTED]>:
>> Not sure what you are going to get. Can you shorten your functions and
>> specify some example data? Then please tell us what your expected result is.
>>
>> Best,
>> Uwe Ligges
>>
>>
>>
>>
>> david dav wrote:
>> > Dear all,
>> >
>> > I 'd like to keep the names of variables when calling them in a function.
>> > An example might help to understand my problem :
>> >
>> > The following function puts in a new data frame counts and percent of
>> > a data.frame called as "tablo"
>> > the step " nom.chiffr[1] <- names(vari) " is useless as names from the
>> > original data.frame aren't kept in the function environement.
>> >
>> > Hoping I use appropriate R-vocabulary, I thank you for your help
>> >
>> > David
>> >
>> > descriptif <- function (tablo) {
>> >   descriptifvar <- function (vari) {
>> >   table(vari)
>> >   length(vari[!is.na(vari)])
>> >   chiffr <- 
>> > cbind(table(vari),100*table(vari)/(length(vari[!is.na(vari)])))
>> >   nom.chiffr <- rep(NA, dim(table(vari)))
>> >   if (is.null(names(vari))) nom.chiffr[1] <- paste(i,"") else
>> >   nom.chiffr[1] <- names(vari)
>> >   chiffr <- data.frame (  names(table(vari)),chiffr)
>> >   rownames(chiffr) <- NULL
>> >   chiffr <- data.frame (nom.chiffr, chiffr)
>> >   return(chiffr)
>> >   }
>> >
>> >   res <- rep(NA, 4)
>> >   for (i in 1 : ncol(tablo))
>> >   res <- rbind(res,descriptifvar(tablo[,i]))
>> >   colnames(res) <- c("variable", "niveau", "effectif", "pourcentage")
>> > return(res[-1,])
>> > }
>> > # NB I used this function on a data.frame with only factors in
>> >
>> > __
>> > R-help@stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide 
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R graphics display window

2007-08-17 Thread Duncan Murdoch
On 16/08/2007 7:35 PM, Felipe Carrillo wrote:
> Hi all:
> How can the R graphics window be customized
> programmatically? Either minimized,maximized or change
> the size of the default that ships with R.

Which device are you working with?  Most of them allow the size to be 
selected in the initial call to open the window, e.g.

windows(2,2) for a very small window.  (The sizes are in inches, 
assuming your monitor reports the size of its pixels correctly.)

options("device") allows you to choose a new default; e.g.

options(device=function() windows(2,2))

to always get very small windows.

I don't know if any of the devices support programmatic changes from R 
code, but in Windows you could do most changes by sending Windows 
messages to the window or doing Windows API calls.  You can get the 
handle using getWindowsHandle(), and then you'll need to write C code to 
do the work.

Duncan Murdoch

> Thanks
> 
>  Felipe D. Carrillo
>   Fishery Biologist
>   US Fish & Wildlife Service
>   Red Bluff, California 96080
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with scatterplot3d

2007-08-13 Thread Duncan Murdoch
On 8/13/2007 3:03 PM, Ryan Briscoe Runquist wrote:
> Hello,
> 
> I am having a bit of trouble with scatterplot3d().
> 
> I was able to plot a 3d cloud of points using the following code:
> 
>>my.3dplot<-scatterplot3d(my.coords, pch=19, zlim=c(0,1), scale.y=0.5,
> angle=30, box=FALSE)
> 
> where my.coords is a data frame that contains x, y, and z coordinates for
> grid points whose elevation we sampled.
> 
> The problem occurs when I try to add points using points3d.  I tried to
> follow the code in the examples of the package pdf.
> 
> First, I tried the following code to add all of the points that I wanted:
> 
>>my.3dplot$points3d(seq(400,600,0.19), seq(600,400,0.295),
> seq(800,500,0.24), seq(1000,1400,0.22), seq(1200,600,0.24),
> seq(1200,1500,0.28), seq(1300,1400,0.205), seq(1700,500,0.26),
> seq(1700,600,0.21), seq(1900,1400,0.255), seq(2300,1400,0.275),
> seq(2600,1300,0.225), seq(2700,400,0.235), seq(2700,1300,0.265),
> seq(3100,1000,0.135), col="blue", type="h", pch=16)

The header to the function (which you can see by evaluating 
my.3dplot$points3d) is

function (x, y = NULL, z = NULL, type = "p", ...)

so you are setting x to seq(400,600,0.19), y to seq(600,400,0.295), etc.

I think you probably want

my.3dplot$points3d(x=c(400, 600, ...),
y=c(600, 400, ...),
z=c(0.19, 0.295, ...), ...)

(where the ... is to be filled in by you.)
> 
> and got the following error:
> Error in seq.default(600, 400, 0.295) : wrong sign in 'by' argument
> 
> So I just tried to add the first point using the following code:
> 
>>my.3dplot$points3d(seq(400,600,0.19), col="blue", type="h", pch=16)
> 
> and got the following error message:
> 
> Error in xyz.coords(x, y, z) : 'x', 'y' and 'z' lengths differ.
> 
> Does anyone know how I can use this function in the scatterplot3d package?

try

my.3dplot$points3d(x=400, y=600, z=0.19, col="blue", type="h", pch=16)

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Artifacts in pdf() of image() (w/o comments)

2007-08-13 Thread Duncan Murdoch
On 8/13/2007 1:33 PM, Michael Kubovy wrote:
> Hi Duncan,
> 
> I was trying to learn to remove the artifacts by setting the  
> parameters of the image so that anti-aliasing wouldn't produce them  
> (analogous to making sure that the screens of two halftone screen  
> process images are in register before combining them so as to avoid  
> Moiré patterns). So, I wasn't complaining; I was looking for  
> instruction. Since the image was computed with R, it's reasonable for  
> me to ask R experts to help me out of what I thought was caused by my  
> ineptitude. (Regarding your question, "If it wasn't a bug, why did it  
> bother you so much?"---there are many things that bother me that are  
> not bugs.)
> 
> Moreover, I'm not opposed to complaining to Apple, once I have been  
> assured that I'm not reporting a bug where there's none.

Let me explain my point of view a bit more:

  - You saw ugly artifacts in a graph you produced.  That's a bug.  The 
question is, what caused it?
  - You rightly asked on R-help.  It might have been a bug in the way 
you were doing things, or a bug in R, or a bug in the way you were 
viewing the image.
  - It was demonstrated that this only appears in Preview, not in 
Acrobat Reader, so it's probably a bug there.

It's only at the last point that I object to what you did:  your 
question quoted below makes it look as though you think Apple's time is 
more valuable than ours.  I remind you that you paid for Preview, and 
you didn't pay for R.  Apple has a stronger obligation to help you than 
any of us do.  My experience with them (and with most other commercial 
software vendors) is that you'll get much worse help from them than from 
us --- but that doesn't mean you shouldn't try.  Perhaps when anyone 
searching for "Mac OSX Preview" on Google shows up a page full of 
unhandled bug reports they'll actually do something.

Duncan Murdoch

> 
> On Aug 13, 2007, at 9:56 AM, Duncan Murdoch wrote:
> 
>> On 8/13/2007 11:43 AM, Michael Kubovy wrote:
>>> But is it a bug? Can a program anti-alias text and line drawings  
>>> and  not bitmaps?
... [deletions] ...
>>>> An alternative to dropping Preview is to report the bug in it to   
>>>> Apple.  Apple has an online bug reporting web page somewhere; I   
>>>> haven't found them as helpful as R-help, but your mileage may vary.
>>>>
>>>> Duncan Murdoch
... [the rest deleted] ...

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Artifacts in pdf() of image() (w/o comments)

2007-08-13 Thread Duncan Murdoch
On 8/13/2007 11:43 AM, Michael Kubovy wrote:
> But is it a bug? Can a program anti-alias text and line drawings and  
> not bitmaps?

Anti-aliasing is the removal of artifacts caused by displaying an image 
on a low-resolution bitmapped display.  Introducing artifacts is a bug.

If it wasn't a bug, why did it bother you so much?  And why do you think 
it's reasonable to complain about it on R-help, but not to complain 
about it to Apple, who are clearly responsible for it?

Duncan Murdoch

> 
> On Aug 13, 2007, at 9:30 AM, Duncan Murdoch wrote:
> 
>> On 8/13/2007 11:07 AM, Michael Kubovy wrote:
>>> Dear Friends,
>>> Thanks for your input.
>>> FYI: Preview doesn't show PDF aliasing in the image I produced if  
>>> I  uncheck the "Anti-alias text and line art" box under the PDF  
>>> tab in  Preferences. So I'm not yet ready to drop Preview from my  
>>> toolbox.
>>
>> An alternative to dropping Preview is to report the bug in it to  
>> Apple.  Apple has an online bug reporting web page somewhere; I  
>> haven't found them as helpful as R-help, but your mileage may vary.
>>
>> Duncan Murdoch
> 
> _
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS: P.O.Box 400400Charlottesville, VA 22904-4400
> Parcels:Room 102Gilmer Hall
>  McCormick RoadCharlottesville, VA 22903
> Office:B011+1-434-982-4729
> Lab:B019+1-434-982-4751
> Fax:+1-434-982-4766
> WWW:http://www.people.virginia.edu/~mk9y/
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Artifacts in pdf() of image() (w/o comments)

2007-08-13 Thread Duncan Murdoch
On 8/13/2007 11:07 AM, Michael Kubovy wrote:
> Dear Friends,
> 
> Thanks for your input.
> 
> FYI: Preview doesn't show PDF aliasing in the image I produced if I  
> uncheck the "Anti-alias text and line art" box under the PDF tab in  
> Preferences. So I'm not yet ready to drop Preview from my toolbox.

An alternative to dropping Preview is to report the bug in it to Apple. 
  Apple has an online bug reporting web page somewhere; I haven't found 
them as helpful as R-help, but your mileage may vary.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Artifacts in pdf() of image() (w/o comments)

2007-08-12 Thread Duncan Murdoch
Michael Kubovy wrote:
> On Aug 12, 2007, at 6:24 AM, Duncan Murdoch wrote:
>
>   
>> Michael Kubovy wrote:
>> 
>>> Dear r-helpers,
>>>
>>> In my previous message there were comments in the code that may  
>>> have  made cutting and pasting awkward. Here it is w/o them.
>>>
>>> I have two questions:
>>>
>>> (1) The following produces a pdf with artifacts. How do I prevent  
>>> them?
>>>
>>>   
>> What artifacts do you see?  It looks like a smoothly varying field  
>> when produced by R 2.5.1 and viewed in Acrobat Reader 6.0 on Windows.
>>
>> Duncan Murdoch
>> 
>>> require(grDevices)
>>> imSize <- 200
>>> lambda <- 10
>>> theta <- 15
>>> sigma <- 40
>>> x <- 1:imSize
>>> x0 <- x / imSize -.5
>>> freq = imSize/lambda
>>> xf = x0 * freq * 2 * pi
>>> f <- function(x, y){r <- -((x^2 + y^2)/(sigma ^2)); exp(r)}
>>> z <- outer(xf, xf, f)
>>> f1 <- function(x, y){cos(.1 * x)}
>>> z1 <- outer(xf, xf, f1)
>>> pdf('gabor.pdf')
>>> image(xf, xf, z * z1, col = gray(250:1000/1000),
>>> xlab = '', ylab =  '', bty = 'n', axes = FALSE, asp = 1)
>>> dev.off()
>>>   
>
> I'm working on a Mac. You're right, Acrobat 6.05 renders the figure  
> nicely, but when it's included in a LaTeX-produced pdf or viewed with  
> the Mac Preview program, a grid of fine white lines is superimposed  
> on the figure. So I believe that it's a matter of aliasing, which I  
> might be able to prevent by adjusting the parameters of the figures.  
> I just don't know enough to figure this out, and would appreciate  
> guidance.
I see the artifacts in Preview on a Mac too.  So it looks to me like a 
Mac bug.

Preview is actually pretty poor at graphics display; see 
<http://www.geuz.org/pipermail/gl2ps/2007/000223.html>.

My only suggestion is not to use Preview.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to store the parameter estimated by nls( ) to a variable?

2007-08-12 Thread Duncan Murdoch
Yuchen Luo wrote:
> Dear Colleagues.
>
> I believe this should be a problem encountered by many:
>
> nls( ) is a very useful and efficient function to use if we are just to
> display the estimated value on screen. What if we need R to store the
> estimated parameter in a variable?
>
> For example:
>
> x=rnorm(10, mean=1000, sd=10)
>
> y=x^2+100+rnorm(10)
>
> a=nls(y~(x^2+para),control=list(maxiter = 1000, minFactor=0.5
> ^1024),start=list(para=0.0))
>
> How to store the estimated value of para in this case, in a variable, say,
> b?
>
> It is easy to display a and find all the information. How ever, I need to
> fit a different set of x and y in every loop of my code and I need to store
> the estimated values for further use. I have checked both the online manual
> and several S-plus books but no example as such showed up.
>
> Your help will be highly appreciated!

coef(a) will get what you want.  coef() works for most modelling 
functions where it makes sense.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Artifacts in pdf() of image() (w/o comments)

2007-08-12 Thread Duncan Murdoch
Michael Kubovy wrote:
> Dear r-helpers,
>
> In my previous message there were comments in the code that may have  
> made cutting and pasting awkward. Here it is w/o them.
>
> I have two questions:
>
> (1) The following produces a pdf with artifacts. How do I prevent them?
>   

What artifacts do you see?  It looks like a smoothly varying field when 
produced by R 2.5.1 and viewed in Acrobat Reader 6.0 on Windows.

Duncan Murdoch
> require(grDevices)
> imSize <- 200
> lambda <- 10
> theta <- 15
> sigma <- 40
> x <- 1:imSize
> x0 <- x / imSize -.5
> freq = imSize/lambda
> xf = x0 * freq * 2 * pi
> f <- function(x, y){r <- -((x^2 + y^2)/(sigma ^2)); exp(r)}
> z <- outer(xf, xf, f)
> f1 <- function(x, y){cos(.1 * x)}
> z1 <- outer(xf, xf, f1)
> pdf('gabor.pdf')
> image(xf, xf, z * z1, col = gray(250:1000/1000),
> xlab = '', ylab =  '', bty = 'n', axes = FALSE, asp = 1)
> dev.off()
>
> (2) I would like the output to be clipped to a circle, i.e., anything
> outside the circle tangent to the sides of the square should be
> transparent. How can I do that?
Set the values there to NA?  I'm not sure how ragged that will make the 
edge...

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Namespace problem

2007-08-08 Thread Duncan Murdoch
Dimitri Mahieux wrote:
> Hi All,
>
> I have some questions about making a R-package. I would like to use a 
> namespace. The package contains analysis functions and also
> a graphical user interface. I would like to allow user to use only the 
> analysis function and not the GUI functions which are mainly
> bindings to graphical elements. I have exported analysis functions using 
> export directives in a namespace file but when I want to use
> the GUI, it seems that all the GUI functions are unknown.
>
> Is there a way to solve this problem ?
>   
If you don't export the functions, they won't normally be visible 
outside your package, but you can still use the ":::" notation to get 
them, e.g.

mypackage:::myfunction

gets myfunction even if it was not exported.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] lm( ) for log10-transformed data

2007-08-07 Thread Duncan Murdoch
On 8/7/2007 2:58 PM, Kim Milferstedt wrote:
> Dear help-list,
> 
> I would like to perform a linear regression on the log10 of the two 
> vectors ov.mag.min and res.600nm. The slope and intercept of the 
> regression I use to plot a wider range of ov.mag.min in a double log plot.
> 
> For a linear regression on only tow points, wouldn't I expect the 
> results for two.points.min to match pretty exactly res.600nm? It does 
> not seem to be the case here. I manually calculated the slope and 
> intercept and got values of -0.71 and 1.5 that seem to work alright. 
> What is it that I am missing here?
> 
> Thanks already for your help,
> 
> Kim
> 
> ov.mag.min <- c(50, 1000)
> res.600nm <- c(2.0, 0.231)
> 
> 
> lm.line.min <- lm(  log(ov.mag.min,10)
>  ~
>  log(res.600nm,10)
>  )
> 
> intercept.min  <- lm.line.min$coefficients[1]
> slope.min <- lm.line.min$coefficients[2]
> 
> 
> two.points.min <- log(ov.mag.min,10)
> 
> round(res.600nm,2) == 
> round(10^(two.points.min*slope.min+intercept.min),2)
> 
> round(res.600nm,2)
> round(10^(two.points.min*-0.71+1.5),2)

The convention in the lm() function is to express a model as
response ~ predictor.  So you should expect

round(ov.mag.min,2) == round(10^(log(res.600nm, 
10)*slope.min+intercept.min),2)

not the other way around, and this does evaluate to two TRUE values.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] - round() strange behaviour

2007-08-06 Thread Duncan Murdoch
On 06/08/2007 5:46 AM, John Logsdon wrote:
> In R you may be tempted to use rounding to index something in an array.  
> Hence 
> my concern and suggestion that there be another argument to round() (and 
> signif()) that explicitly sets the rounding mechanism.  
> 
> In Fortran IDNINT does as I would expect.  You could do floor(x+0.5) but many 
> people, myself included before this conversation, will unwittingly round and 
> it will almost always work but the exception is something that may even be 
> difficult to reproduce where random numbers are involved without setting the 
> seed.  

As you mention, where you want to round 0.5 upwards, you can use the 
function

roundup <- function(x, digits=0) {
   factor <- 10^digits
   trunc(x*factor + 0.5)/factor
}

But beware of floating point representations:  most decimal numbers 
ending in 5 can't be represented exactly, so you'll see oddities like this:

 > roundup(2.45, 1)
[1] 2.5
 > roundup(2.4 + 0.05, 1)
[1] 2.4

which is partially explained by this:

 > 2.45 - (2.4 + 0.05)
[1] 4.440892e-16

I suspect the same sort of thing would happen in Fortran's IDNINT though 
it might be harder to see, because most Fortran compilers do fairly 
substantial optimizations, and it might be that they actually store 2.4 
+ 0.05 and 2.45 as the same constant.  So I don't think round() leaves 
any new traps for the unwary:  if x = 0.5 is the result of a 
calculation, it might actually be stored as 0.499 and round(x) 
should return 0 even using roundup().

Duncan Murdoch

> In this context you cannot leave rounding until the end of course!  Clearly 
> in 
> an arithmetic context, rounding should always be left to the end but I don't 
> think that is to avoid rounding-to-even but just to avoid unnecessary loss of 
> precision in the calculation.  Ask most engineers - and even physicists - and 
> I suspect they would not be aware of this debate even though it dates from 
> the 1940s.
> 
> On Monday 06 August 2007 10:31:22 Jim Lemon wrote:
>> (Ted Harding) wrote:
>>> ...
>>> Thus "always up" or "always down" means that the difference between
>>> rounded numbers is always the same as between the unrounded numbers
>>> which for other methods the differences can differ by 2.0.
>>> This may or may not matter, but it is something to think about
>>> when choosing a rounding method.
>> Ah, but Ted, this is why, as I remarked in a private message to the
>> original poster, we were also taught never to round until the final
>> result. Had I not had a rather extended debate with an engineer who
>> apparently thought that one could get away with successive rounding, I
>> would not be so sensitive on the issue.
>>
>> Jim
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html and provide commented, minimal,
>> self-contained, reproducible code.
> 
> 
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] request

2007-08-04 Thread Duncan Murdoch
On 04/08/2007 1:41 AM, zahid khan wrote:
>  I want to calculate the commulative sum of any numeric vector with the 
> following command but this following command does not work  "comsum"
>   My question is , how we can calculate the commulative sum of any numeric 
> vector with above command

In English the spelling is "cumulative", but the help.search() function 
can find the answer with small misspellings:

help.search("commulative sum")

yields cumsum as the answer.

Duncan Murdoch

>   Thanks
> 
> 
> Zahid Khan
> Lecturer in Statistics
> Department of Mathematics
> Hazara University Mansehra.
>
> -
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Opening a script with the R editor via file association (on Windows)

2007-08-03 Thread Duncan Murdoch
On 03/08/2007 7:16 PM, Christopher Green wrote:
> Is there an easy way to open an R script file in the R Editor found in
> more recent versions of R on Windows via a file association? I am looking
> for functionality akin to how the ".ssc" file extension works for S-Plus:
> upon double-clicking on a ".R" file, Rgui.exe starts up and loads the script 
> file in the R Editor.
> 
> As far as I can tell, Rgui.exe does not have a command line option to load
> a file (so associating ".R" with "Rgui.exe %1" won't work). I can get Windows
> to start Rgui.exe when I double-click on a script file, but that's about it.
> I also don't see any way to have Rgui.exe evaluate an expression provided on
> the command line (which would allow "file.edit(%1)"). I also thought about
> creating a custom .First calling 'file.edit' in a batch file, but then I'd 
> have
> to start R, load the .First file, then quit and restart R, so that's out.
> 
> Is there an easy way to do this without resorting to some other R GUI?

Easy?  Not sure.  But the following works:

Set up the association as

"F:\R\R-2.5.1\bin\Rgui.exe" --args "%1"

(with obvious modifications to the path) and put this line in your 
RHOME/etc/Rprofile.site file:

utils::file.edit(commandArgs(TRUE))

You could make things more sophisticated if you don't want a blank edit 
window to open in case you're not using this shortcut.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sourcing commands but delaying their execution

2007-08-03 Thread Duncan Murdoch
On 8/3/2007 3:01 PM, Liaw, Andy wrote:
> Here's one possibility:
> 
> The file "garbage.R" has
> 
>   x <- rnorm(100)
>   print(summary(x))
> 
> You can do:
> 
>   cmds <- parse(file="garbage.R", n=NA)
> 
> and when you want to execute those commands, do
> 
>   eval(cmds)

And since it's Friday afternoon, I'll suggest something that allows the 
commands to be broken into two parts and executed separately (but which 
is ridiculous overkill for this problem):

Put

   x <- rnorm(100)
   divider
   print(summary(x))

into your file, then

   cmds <- parse(file="garbage.R", n=NA)

as in Andy's suggestion.  Then find the dividing line using

   divider <- which(unlist(lapply(cmds, deparse)) == "divider")

and then

   part_one <- 1:(divider-1)
   part_two <- (divider+1):length(cmds)

Finally, execute as

   eval(cmds[part_one])
   MORE_COMMANDS
   eval(cmds[part_two])

Duncan Murdoch
> 
> Andy 
> 
> From: Dennis Fisher
>> 
>> Colleagues:
>> 
>> I have encountered the following situation:
>>  SERIES OF COMMANDS
>>  source("File1")
>>  MORE COMMANDS
>>  source("File2")
>> 
>> Optimally, I would like File1 and File2 to be merged into a single  
>> file (FileMerged).  However, if I wrote the following:
>>  SERIES OF COMMANDS
>>  source("FileMerged")
>>  MORE COMMANDS
>> 
>> I encounter an error: the File2 portion of FileMerged contains  
>> commands that cannot be executed properly until "MORE COMMANDS" are  
>> executed.  Similarly, sourcing FileMerged after MORE COMMANDS does  
>> not work because MORE COMMANDS requires the information from the  
>> File1 portion of FileMerged.
>> 
>> I am looking for a means to source FileMerged but not execute 
>> some of  
>> the commands immediately.  Functionally this would look like:
>>  SERIES OF COMMANDS
>>  source("FileMerged")# but withhold execution of 
>> some of the commands
>>  MORE COMMANDS
>>  COMMAND TO EXECUTE THE WITHHELD COMMANDS
>> 
>> Does R offer some option to accomplish this?
>> 
>> Dennis
>> 
>> Dennis Fisher MD
>> P < (The "P Less Than" Company)
>> Phone: 1-866-PLessThan (1-866-753-7784)
>> Fax: 1-415-564-2220
>> www.PLessThan.com
>> 
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> 
>> 
> 
> 
> --
> Notice:  This e-mail message, together with any attachments,...{{dropped}}
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Re : change the names of all listed objects

2007-08-03 Thread Duncan Murdoch
On 8/3/2007 11:28 AM, justin bem wrote:
> It not too simple what ls return the variable that have been create in your 
> environment even if you change their names, ls will not return "a1" "b1" ...
> 
> The names attribute in OOP of an object is just an attribute and it is 
> different with an instance of the object. ls() show instance
> 
> But you can try this :
> 
> a<-10
>> ls()
> [1] "a"
> 
> assign(paste(deparse(substitute(a)),"1",sep=""),a)  # here I 
> create a new instance with name   
>   # a1 and the same value than a
> rm(a) 
># In destroy the original.

The use of deparse(substitute(a)) suggests you want to do this in a 
function, but then your rm() will only remove the local copy.  Writing a 
gemeral purpose function for this is tricky, because it's not obvious 
what should happen in certain weird cases.  For example:

rename( c, collect )

to rename the c() function to collect():  should it really try to go 
into the base environment and delete the c object?  That would be fairly 
disastrous if it succeeded.  But if it found a c() function in the 
global environment, removing it from there might be sensible (maybe even 
if this rename request were executed from a function, rather than at the 
top level).

Duncan Murdoch

> 
>>ls()
> [1] "a1"
> 
> 
>  
> Justin BEM
> BP 1917 Yaoundé
> Tél (237) 99597295
> (237) 22040246
> 
> - Message d'origine 
> De : Luca Laghi <[EMAIL PROTECTED]>
> À : r-help@stat.math.ethz.ch
> Envoyé le : Vendredi, 3 Août 2007, 15h23mn 01s
> Objet : [R] change the names of all listed objects
> 
> Dear list members,
> I have created seven objects, from a to g, so that ls() gives me
> [1] "a" "b" "c" "d" "e" "f" "g"
> 
> how can I automatically change their names in
> 
> "a1" "b1" "c1" "d1" "e1" "f1" "g1"
> 
> It seems simple, ut it is driving me mad.
> Thank you very much for your help.
> Luca Laghi
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> 
> 
> 
> 
>   
> _ 
> 
> l 
>   [[alternative HTML version deleted]]
> 
> 
> 
> 
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] change the names of all listed objects

2007-08-03 Thread Duncan Murdoch
On 8/3/2007 10:23 AM, Luca Laghi wrote:
> Dear list members,
> I have created seven objects, from a to g, so that ls() gives me
> [1] "a" "b" "c" "d" "e" "f" "g"
> 
> how can I automatically change their names in
> 
> "a1" "b1" "c1" "d1" "e1" "f1" "g1"
> 
> It seems simple, ut it is driving me mad.

R doesn't have a "rename" operation, so you need to copy the objects and 
then delete the original.  For example:

# create a vector of the names of your objects
namelist <- letters[1:7]

for (i in seq_along(namelist)) {
   oldname <- namelist[i]

   # compute a new name from the old one
   newname <- paste(oldname, "1", sep="")

   # create a variable with the new name
   assign(newname, get(oldname))

   # delete the old object
   rm(list=oldname)
}


The code above should work in simple cases where you run it in the 
console and it works on objects in the global workspace.  If you want to 
write a function to do this things get more complicated, because you 
want to make the assignment in the same place the function found the 
original.

There are quicker ways (using mget() and apply()), but they'd really 
just be doing the same as the above in a less clear way.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to properly finalize external pointers?

2007-08-03 Thread Duncan Murdoch
On 8/3/2007 9:19 AM, Jens Oehlschlägel wrote:
> Dear R .Call() insiders,
> 
> Can someone enlighten me how to properly finalize external pointers in C code 
> (R-2.5.1 win)? What is the relation between R_ClearExternalPtr and the 
> finalizer set in R_RegisterCFinalizer?
> 
> I succeeded registering a finalizer that works when an R object containing an 
> external pointer is garbage collected. However, I have some difficulties 
> figuring out how to do that in an explicit closing function. 
> 
> I observed that 
> - calling R_ClearExternalPtr does not trigger the finalizer and is dangerous 
> because it removes the pointer before the finalizer needs it at 
> garbage-collection-time (no finalization = memory leak)
> - calling the finalizer directly ensures finalization but now the finalizer 
> is called twice (once again at garbage collection time, and I did not find 
> documentation how to unregister the finalizer)
> - It works to delete the SEXP external pointer object but only if not calling 
> R_ClearExternalPtr (but why then do we need it?) Furthermore it is 
> unfortunate to delay freeing the external pointers memory if I know during 
> runtime that it can be done immediately.
> 
> Shouldn't R_ClearExternalPtr call the finalizer and then unregister it? (this 
> would also work when removing the SEXP external pointer object is difficult 
> because it was handed over to the closing function directly as a parameter)

I think we want R_ClearExternalPtr to work even if the finalizer would 
fail (e.g. to clean up when there was an error when trying to build the 
external object).

So I'd suggest that when you want to get rid of an external object 
immediately, you call the finalizer explicitly, then call 
R_ClearExternalPtr.  The documentation doesn't address the question of 
whether this will clear the registered finalizer so I don't know if 
you'll get a second call to the finalizer during garbage collection, but 
even if you do, isn't it easy enough to do nothing when you see the null 
ptr, as you do below?

By the way, questions about programming at this level are better asked 
in the R-devel group.

Duncan Murdoch

> Best regards
> 
> 
> Jens Oehlschlägel
> 
> 
> // C-code
> 
> static void rindex_finalize(SEXP extPtr){
>   pINT ptr = R_ExternalPtrAddr(extPtr);
>   if(ptr){
> Free(ptr);
> Rprintf("finalized\n");
>   }else{
> Rprintf("nothing to finalize\n");
>   }
>   return;
> }
> 
> 
> SEXP rindex_open(
>   SEXP Sn
> ){
>   int i,n = INTEGER(Sn)[0];
>   pINT ptr = Calloc(sizeof(INT)*n, INT);
>   SEXP extPtr, ret;
>   for (i=0;i ptr[i] = i;
>   }
>   extPtr = R_MakeExternalPtr(ptr, install("Rindex_extPtr"), R_NilValue);
>   R_RegisterCFinalizer(extPtr, rindex_finalize);
> 
>   PROTECT(ret = allocVector(VECSXP, 1));
>   SET_VECTOR_ELT(ret,0,extPtr);
>   UNPROTECT(1);
>   return ret;
> }
> 
> SEXP rindex_close(
>   SEXP obj
> ){
>   int i, n= 10;
>   SEXP ret, extPtr=VECTOR_ELT(obj, 0);
>   pINT p, ptr = R_ExternalPtrAddr(extPtr);
> 
>   PROTECT(ret = allocVector(INTSXP, n));
>   p = INTEGER(ret);
>   for (i=0;i Rprintf("ptri=%d\n",ptr[i]);
> p[i] = ptr[i];
>   }
> 
>   /* this does finalize immediately but at next garbage collection again
>   rindex_finalize(extPtr);
>   */
> 
>   /* this must not called otherwise the pointer is gone at garbage collection 
> time
>   R_ClearExternalPtr(extPtr);
>   */
> 
>   /* this triggers the finalizer but only at next garbage collection */
>   SET_VECTOR_ELT(obj,0,R_NilValue);
> 
>   UNPROTECT(1);
>   return ret;
> }
> 
> 
> # R-Code
> initRindex <- function(){
>   dyn.load(file.path(.libPaths(), "rindex", "libs", paste("rindex", 
> .Platform$dynlib.ext, sep = "")))
> }
> 
> doneRindex <- function(){
>   dyn.unload(file.path(.libPaths(), "rindex", "libs", paste("rindex", 
> .Platform$dynlib.ext, sep = "")))
> }
> 
> 
> openRindex <- function(n=10){
>   .Call("rindex_open", as.integer(n))
> }
> 
> closeRindex <- function(extPtr){
>   .Call("rindex_close", extPtr)
> }
> 
> if (FALSE){
>   # now try it
>   require(rindex)
> 
>   initRindex()
> 
>   extPtr <- openRindex()
>   extPtr
>   extPtr2 <- closeRindex(extPtr)
>   extPtr2
>   gc()
> 
>   extPtr <- openRindex()
>   extPtr2 <- extPtr
>   extPtr2
>   rm(extPtr)
>   gc()
>   extPtr2
>   rm(extPtr2)
>   gc()
>   extPtr2
> 
>   doneRindex()
> }
> 
> 
>> version
>_   

Re: [R] Package manual examples - 'unexpected$undefined' errors

2007-07-30 Thread Duncan Murdoch
David Pain wrote:
> Trying out an unfamiliar package, the natural thing is to use the examples
> given in the package's manual - hopefully, the writers of the package
> wouldn't include examples which didn't work!
>
> Recently, though, I've been getting 'unexpected$undefined' error messages
> when doing this, despite having copy/pasted the text from the manual (taking
> out hard breaks on the way).
>
> Moreover, I've had error messages for commands which I've previously had
> work fine.
>
> For instance, this from Zelig
>
> z.out <­ zelig(vote ~ race + educate, model = "logit", data = turnout)
>
> has at different times worked fine and thrown up the error message.
>
> Any help gratefully received.
>
>   [[alternative HTML version deleted]]
It's hard to say exactly what's going wrong, but a guess is that in your 
workspace you have an object which is somehow conflicting with an object 
in the package.  Try starting R with the --vanilla command line option
and if the errors go away, that's why.

I don't know whether this applies to the Zelig package, but packages 
that don't define namespaces are fragile in that their internal 
functions can be masked by same-named functions in your workspace.  Even 
if the package does have a namespace, you can mask functions from it 
that you call:  for example, if you had a function called zelig (perhaps 
because you used fix(zelig) to make a small change to the existing one), 
your line above would call yours, not the original.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plot3d labels

2007-07-20 Thread Duncan Murdoch
On 20/07/2007 5:23 AM, Birgit Lemcke wrote:
> Hello Jim,
> 
> thanks for your answer but  I still have problems with the labels.  
> Perhaps you can help me a second time.
> 
> I have the output of cmdscale and it looks like this:
> 
>[,1]  [,2]  [,3]
> Anth_cap  -0.011833788 -0.1091355289 -0.0222467839
> Anth_crin -0.008178993 -0.0219545815 -0.0076695878
> Anth_eck   0.026900827 -0.0422055677 -0.1340542844
> Anth_gram -0.010860990  0.0080112322  0.0201743866.
> 
> In the next step I created 3 vectors out of the three columns
> 
> PCoA1<-PCoA[,1]
> PCoA2<-PCoA[,2]
> PCoA3<-PCoA[,3]
> 
> After that I plotted the 3 vectors
> 
> plot3d(PCoA1,PCoA2,PCoA3, type="p", col=rainbow(1000),size=5)

There's no need to extract the 3 columns:  you could just use

plot3d(PCoA, type="p", col=rainbow(1000),size=5)

with the data above.
> 
> and now I try to handle this text3d function and label the points in  
> the graphic with the names in the first column. But I am a beginner  
> and don´t know the syntax for this in the text3d.
> 
> I tried to make vectors out of every row like this:
> 
> Anth_cap<- PCoA[1,]
>  > Anth_crin<- PCoA[2,]
>  > Anth_eck<- PCoA[3,]
>  > Anth_gram<- PCoA[4,]
>  > Anth_insi<- PCoA[5,]
>  > Anth_laxi<- PCoA[6,].
> 
> and than tried to implement this in the text3d:
> 
> text3d( c(Anth_cap,
> Anth_crin,

I think all you need is

text3d(PCoA, text=Nam)

but you might want to set the adj argument if you want the labels offset 
from the points, and you might want type="n" in the original plot3d call 
if you don't want the points to interfere with the labels.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] can I paste 'newline'?

2007-07-19 Thread Duncan Murdoch
On 19/07/2007 7:41 PM, runner wrote:
> It is ok to bury a reg expression '\n' when using 'cat', but not 'paste'. 
> e.g.
> 
> cat ('I need to move on to a new line', '\n', 'at here') # change line!
> paste ('I need to move on to a new line', '\n', 'at here') # '\n' is just a
> character as it is.
> 
> Is there a way around pasting '\n' ? Thanks a lot.

What do you want to get?  Do you want a two element vector?  Then use 
c().  Do you want a one element vector that prints on two lines?  Use 
either form, they both work (but you need to use cat() to do the display).

 > x <- paste ('I need to move on to a new line', '\n', 'at here')
 > cat(x)
I need to move on to a new line
  at here>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] reading in "!" - delimited file

2007-07-17 Thread Duncan Murdoch
On 17/07/2007 5:25 PM, Dimitri Liakhovitski wrote:
> I have to read in a file that is "!" delimited.
> Would it be correct to use the following syntax:
> 
> Data<-read.delim(file.choose(),sep="!")
> 
> Or would it be wrong? I am asking rather than trying it just because I
> have 3.5 million cases to read in.

If you have 3.5 million cases to read, you should specify the column 
classes.  I'd recommend setting nrows to a small number for a few tries 
first, until you get it right.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] A simple question

2007-07-17 Thread Duncan Murdoch
On 7/17/2007 3:36 PM, Gang Chen wrote:
> Hi all,
> 
> I am a newbie of R, and have a very simple question. When I run the  
> following t test
> 
> result = t.test(weight ~ group)
> 
> If I want to get the t value, I can do
> 
> tvalue = result$statistic
> 
> with tvalue being the following:
> 
> t
> 1.191260
> 
> However, if I just want the number 1.191260, not the character "t",  
> how can I achieve that?

as.numeric(result$statistic)

will give it to you.  But the value you have is already just as useful: 
  it's just a vector with a named entry.  You can do calculations with 
it without stripping off the name.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] looking at a function's code

2007-07-16 Thread Duncan Murdoch
On 16/07/2007 8:02 AM, Walter Paczkowski wrote:
> Good morning,
> 
> I'd like to look at the code for the R function head.  When I type just the 
> word head, I get back
> 
> function(x, ...)
> UseMethod("head")
> 
> 
> 
> I expected to see several lines of R code.  Any suggestions?

Even though it's not very informative, that really is the source for 
that function.  For instructions on how to see the more useful stuff, 
see Uwe Ligges' article in the Oct 2006 R News (available at 
http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf).

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Break during the recursion?

2007-07-15 Thread Duncan Murdoch
On 15/07/2007 11:36 AM, Atte Tenkanen wrote:
>> On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
>>>> On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
>>>>> Hi,
>>>>>
>>>>> Is it possible to break using if-condition during the recursive 
>>>> function?
>>>> You can do
>>>>
>>>>  if (condition) return(value)
>>>>
>>>>> Here is a function which almost works. It is for inorder-tree-
>>>> walk. 
>>>>> iotw<-function(v,i,Stack,Indexes) # input: a vector and the 
>> first 
>>>> index (1), Stack=c(), Indexes=c().
>>>>> {
>>>>>   print(Indexes)
>>>>>   # if (sum(i)==0) break # Doesn't work...
>>>>if (sum(i)==0) return(NULL)
>>>>
>>>> should work.
>>>>
>>>> Duncan Murdoch
>>> Hmm - - - I'd like to save the Indexes-vector (in the example 
>> c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready. 
>>
>> This seems more like a problem with the design of your function 
>> than a 
>> question about R.  I can't really help you with that, because your 
>> description of the problem doesn't make sense to me.  What does it 
>> mean 
>> to do an inorder tree walk on something that isn't a tree?
>>
>> Duncan Murdoch
> 
> The symbols in vector v have been originally derived from "tree". See
> 
> http://users.utu.fi/attenka/Tree.jpg
> 
> But perhaps there's another way to do this, for instance by using loops and 
> if-conditions? 

Or perhaps by doing the tree walk on the tree, before you collapse it 
into a vector.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Break during the recursion?

2007-07-15 Thread Duncan Murdoch
On 15/07/2007 10:33 AM, Atte Tenkanen wrote:
>> On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
>>> Hi,
>>>
>>> Is it possible to break using if-condition during the recursive 
>> function?
>> You can do
>>
>>  if (condition) return(value)
>>
>>> Here is a function which almost works. It is for inorder-tree-
>> walk. 
>>> iotw<-function(v,i,Stack,Indexes) # input: a vector and the first 
>> index (1), Stack=c(), Indexes=c().
>>> {
>>> print(Indexes)
>>> # if (sum(i)==0) break # Doesn't work...
>>  if (sum(i)==0) return(NULL)
>>
>> should work.
>>
>> Duncan Murdoch
> 
> Hmm - - - I'd like to save the Indexes-vector (in the example 
> c(8,4,9,2,10,5,11,1,3)) and stop, when it is ready. 

This seems more like a problem with the design of your function than a 
question about R.  I can't really help you with that, because your 
description of the problem doesn't make sense to me.  What does it mean 
to do an inorder tree walk on something that isn't a tree?

Duncan Murdoch


> 
> The results are enclosed to the end.
> 
> Atte
> 
>>> 
>>> if (is.na(v[i])==FALSE & is.null(unlist(v[i]))==FALSE)
>>> {Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
>>> Indexes=c(Indexes,Stack[1])
>>> Stack=pop.stack(Stack)$vector
>>> Indexes=c(Indexes,Stack[1])
>>> i=2*Stack[1]+1
>>> Stack=pop.stack(Stack)$vector
>>> iotw(v,i,Stack,Indexes)
>>> }
>>>
>>>
>>>> v=c(`-`,`+`,1,`^`,`^`,NA,NA,"X",3,"X",2)
>>>> Stack=c()
>>>> Indexes=c()
>>>> iotw(v,1,Stack,Indexes)
>>> NULL
>>> NULL
>>> NULL
>>> NULL
>>> NULL
>>> [1] 8 4
>>> [1] 8 4
>>> [1] 8 4 9 2
>>> [1] 8 4 9 2
>>> [1] 8 4 9 2
>>> [1]  8  4  9  2 10  5
>>> [1]  8  4  9  2 10  5
>>> [1]  8  4  9  2 10  5 11  1
>>> [1]  8  4  9  2 10  5 11  1
>>> [1]  8  4  9  2 10  5 11  1  3
>>> Error in if (is.na(v[i]) == FALSE & is.null(unlist(v[i])) == 
>> FALSE) { : 
>>> argument is of length zero
>>>
>>> Regards,
>>>
>>> Atte Tenkanen
>>> University of Turku, Finland
>>>
> 
> 
>> iotw(v,1,Stack,Indexes)
> NULL
> NULL
> NULL
> NULL
> NULL
> [1] 8 4
> [1] 8 4
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1] 8 4 9 2 5 1
> [1] 8 4 9 2 5 1
> [1] 8 4 9 2 5 1 3
> [1] 8 4 9 2 5 1 3
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1] 8 4 9 2 5 1
> [1] 8 4 9 2 5 1
> [1] 8 4 9 2 5 1 3
> [1] 8 4 9 2 5 1 3
> [1] 8 4
> [1] 8 4
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1  3
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> 

Re: [R] Break during the recursion?

2007-07-15 Thread Duncan Murdoch
On 15/07/2007 10:06 AM, Atte Tenkanen wrote:
> Hi,
> 
> Is it possible to break using if-condition during the recursive function?

You can do

  if (condition) return(value)

> 
> Here is a function which almost works. It is for inorder-tree-walk. 
> 
> iotw<-function(v,i,Stack,Indexes) # input: a vector and the first index (1), 
> Stack=c(), Indexes=c().
> {
>   print(Indexes)
>   # if (sum(i)==0) break # Doesn't work...

if (sum(i)==0) return(NULL)

should work.

Duncan Murdoch

>   
>   if (is.na(v[i])==FALSE & is.null(unlist(v[i]))==FALSE)
>   {Stack=c(i,Stack); i=2*i; iotw(v,i,Stack,Indexes)}
>   Indexes=c(Indexes,Stack[1])
>   Stack=pop.stack(Stack)$vector
>   Indexes=c(Indexes,Stack[1])
>   i=2*Stack[1]+1
>   Stack=pop.stack(Stack)$vector
>   iotw(v,i,Stack,Indexes)
> }
> 
> 
>> v=c(`-`,`+`,1,`^`,`^`,NA,NA,"X",3,"X",2)
>> Stack=c()
>> Indexes=c()
> 
>> iotw(v,1,Stack,Indexes)
> NULL
> NULL
> NULL
> NULL
> NULL
> [1] 8 4
> [1] 8 4
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1] 8 4 9 2
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1
> [1]  8  4  9  2 10  5 11  1  3
> Error in if (is.na(v[i]) == FALSE & is.null(unlist(v[i])) == FALSE) { : 
>   argument is of length zero
> 
> Regards,
> 
> Atte Tenkanen
> University of Turku, Finland
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Pairlist of pairlsit assembly howto

2007-07-15 Thread Duncan Murdoch

(This isn't important to your question, but those aren't pairlists. 
Pairlists are rarely used in R code, except implicitly in the way R 
stores parsed code.)

On 15/07/2007 10:00 AM, Johannes Graumann wrote:
> Hy guys,
> 
> I'm trying something like this
> 
> minbins <- list()
> for (minute in sequence(3)) {
> minbins[minute] <- list(data="a",variable="b")
> }

You want to use

minbins[[minute]] <- list(data="a",variable="b")

The difference between [[ ]] and [ ] is that the former works on the 
element, the latter works on a subset.  So your version tried to change 
a subset of length 1 into a subset of length 2, which generates the 
warnings.  You want to assign a list of length 2 as an element of minbins.

Duncan Murdoch
> 
> And it doesn't work ...
> Warning messages:
> 1: number of items to replace is not a multiple of replacement length in:
> minbins[minute] <- list(data = "a", variable = "b") 
> 2: number of items to replace is not a multiple of replacement length in:
> minbins[minute] <- list(data = "a", variable = "b") 
> 3: number of items to replace is not a multiple of replacement length in:
> minbins[minute] <- list(data = "a", variable = "b")
> 
> What am I doing wrong and how to do this properly?
> 
> Thanks, Joh
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] return() in nested functions

2007-07-14 Thread Duncan Murdoch
On 14/07/2007 7:16 AM, Mark Hempelmann wrote:
> Dear WizaRds,
> 
>   After consulting different sources I am still unable to understand the 
> correct use of return() in nested functions. To illustrate the problem:

return() knows nothing about nested functions.  It just returns from the 
current function.

In most respects, nested functions are just like any other functions in 
R.  The only important difference is the attached environment, which 
affects what is visible from within the function, and where <<- stores 
results.

> 
> f <- function(x,y,type){
> 
>   est1<-function(x,y){
>   z=x+y
>   out(x,y,z)}
> 
>   est2<-function(x,y){
>   z=x*y
>   out(x,y,z)}
> 
>   out<-function(x,y,z)
>   return(x,y,z)

Don't ignore the warning you saw from this!  Deprecated things 
eventually become defunct. You want return(list(x, y, z))

> 
> if (type=="est1") est1(x,y)
> if (type=="est2") est2(x,y)
> }
> 
> test<-f(1,2,type="est1") # gives Null for test

The result of the first if is the value from the call to est1.  The 
result of the second if is NULL.  That's what your function returned.

If you had wrapped those calls in return() you'd get what I think you 
expected:

if (type=="est1") return(est1(x,y))
if (type=="est2") return(est2(x,y))

because the return() causes the function to exit and return a value.

Duncan Murdoch

> 
> However, without the second 'if' condition, it works properly:
> Warning message:
> multi-argument returns are deprecated in: return(x, y, z)
>> test
> $x
> [1] 1
> $y
> [1] 2
> $z
> [1] 3
> 
> Basically, the function I am working on is of the above structure, be it
> more complex. I would like f to return the results of function 'out' to 
> the user in the assigned variable, e.g. 'test'. i did consult try() and 
> tryCatch(), but it doesn't seem to be what I am looking for.
> 
> Thank you for your help and understanding
> mark
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] sub-function default arguments

2007-07-12 Thread Duncan Murdoch
On 12/07/2007 7:23 PM, Talbot Katz wrote:
> Hi.
> 
> I have defined a function, f1, that calls another function, f2.  Inside f1 
> an intermediate variable called nm1 is created; it is a matrix.  f2 takes a 
> matrix argument, and I defined f2 (schematically) as follows:
> 
> f2<-function(nmArg1=nm1,...){nC<-ncol(nmArg1); ... }
> 
> so that it expects nm1 as the default value of its argument.  f1 is defined 
> (schematically) as:
> 
> f1<-function(...){result1<-f2(); ... }
> 
> When I ran f1 I got the following error message:
> 
> Error in ncol(nmArg1) : object "nm1" not found.
> 
> If I redefine f1 schematically as:
> 
> f1<-function(...){result1<-f2(nmArg1=nm1); ... }
> 
> it runs okay.  If I have nm1 defined outside of f1 and I run "result1<-f2()" 
> it also runs okay.  So f2 doesn't seem to pick up the default argument value 
> inside the function f1, even when the default argument is defined inside f1. 
>   Is there a way to have the subfunction default arguments recognized inside 
> of a function (perhaps a better protocol for using defaults than what I 
> did?), or do I just have to spell them out explicitly?

Defaults to arguments are evaluated in the evaluation frame of the 
function being called, f2 in your case.  Since nm1 is meaningless within 
f2, you get the error.

If you want nm1 to be meaningful within f2, you could define f2 within 
f1, e.g.

f1<-function(...){
   nm1 <- something
   f2 <- function (...) {}
   result1<-f2(nmArg1=nm1)
   ...
}

(which is the best way to do it), or you could explicitly manipulate the 
environment of f2 (which is an ugly way), or you could store nm1 in some 
place that's visible to both f1 and f2 and use <<- when you set it from 
within f1 (another ugly way, but sometimes less ugly than my second 
suggestion).

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] eMail results out of R

2007-07-12 Thread Duncan Murdoch
On 7/12/2007 9:52 AM, [EMAIL PROTECTED] wrote:
> Hi everyone,
> 
> I did my homework and read the posting guideline :-)
> 
> I want to eMail the results of a computing automatically. So I get the 
> results (the parameters of a garch process) and I want to eMail them to 
> another person. How can I do that?


This will depend on the system you're using.  If the command "emailit" 
would work from the command line on your system, then

system("emailit")

should work from within R.  Writing that command is the hard part, of 
course.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] 3D plot and interactive PDFs

2007-07-11 Thread Duncan Murdoch
On 7/11/2007 9:18 AM, Bruno C. wrote:
> With version 8 of acrobat reader, it is now possible to have 3D in PDf 
> documents.
> Does it exist already an R package who manage to produce 3D plots which can 
> be saved as interactive 3D graphs in a PDF file?

No, not as far as I know.  If you want to help to make it happen, I'd 
suggest working to add it to the GL2PS project 
(http://www.geuz.org/gl2ps) and then it should be automatically 
incorporated into the rgl package.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] integration over a simplex

2007-07-10 Thread Duncan Murdoch
On 7/10/2007 6:57 AM, Robin Hankin wrote:
> Hello
> 
> The excellent adapt package integrates over multi-dimensional
> hypercubes.
> 
> I want to integrate over a multidimensional simplex.  Has anyone
> implemented such a thing in R?
> 
> I can transform an n-simplex to a hyperrectangle
> but the Jacobian is a rapidly-varying (and very lopsided)
> function and this is making adapt() slow.
> 
> [
> A \dfn{simplex} is an n-dimensional analogue of a triangle or  
> tetrahedron.
> It is the convex hull of (n+1) points in an n-dimensional Euclidean  
> space.
> 
> My application is a variant of the Dirichlet distribution:
> With p~D(a), if length(p) = n+1 then the requirement that
> all(p>0) and sum(p)=1 mean that the support of the
> Dirichlet distribution is an n-simplex.

I don't know what shape of simplex you're working with, but I believe 
the subset of an n-cube with coordinates ordered x[1] < x[2] < ... < 
x[n] is a simplex, and the cube can be tiled with n! of those, by 
permuting the order of the coordinates.  So if your function is smooth 
enough at the edges you might be able to map n! copies of it onto a 
cube, and use adapt to integrate over that.

That is:  if f() is your function, defined on 0 < x[1] < x[2] < ... < 
x[n] < 1, define g <- function(x) f(sort(x)), and the integral you want 
is (1/n!) times the integral of g over the unit cube.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fraction ECDF

2007-07-10 Thread Duncan Murdoch
On 7/10/2007 10:36 AM, livia wrote:
> Hi all,
> 
> I would like to plot part of the emperical CDF. Suppose the variable is x, I
> just need the part when x>1,therefore, I am using the following codes. 
> 
> tail <- x>1
> plot(ecdf(x[tail]), do.points=FALSE, verticals=TRUE)
> 
> The "x" value starts from 1, but the yaxs still begins from 0, not the
> corresponding value when "x" is 1. How can I make it match?
> 
> Could anyone give me some advice? Many thanks.

Rather than subsetting the x, I'd just use xlim and ylim arguments to 
plot() to change the range.  For example,

plot(ecdf(x), do.points=FALSE, verticals=TRUE, xlim=c(1, max(x)), 
ylim=c(1-sum(x>1)/length(x), 1))

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extracting S code from a C program

2007-07-08 Thread Duncan Murdoch
On 08/07/2007 12:07 PM, francogrex wrote:
> There is a C program called GPS: 'gamma poisson shrinker' at
> ftp://ftp.research.att.com/dist/gps/
> The algorithms in GPS are based on S-Plus programs written by William
> DuMouchel with support from Columbia University and AT&T Labs. 
> My question is: is there a relatively easy way to extract some of the S code
> from this windows program? Thanks.

No.  From the description, there's no S code there to extract, it's been 
translated to C, and you don't even have the source code.

I'd recommend contacting Dr. DuMouchel to see if he is willing to let 
you have his S code.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Recursion in R ...

2007-07-07 Thread Duncan Murdoch
On 07/07/2007 7:15 AM, (Ted Harding) wrote:
> On 07-Jul-07 10:34:03, Uwe Ligges wrote:
>> Alberto Monteiro wrote:
>>> Ted Harding wrote:
>>>> So I slickly wrote a recursive definition:
>>>>
>>>> Nnk<-function(n,k){
>>>>   if(n==1) {return(k)} else {
>>>> R<-0;
>>>> for(r in (1:k)) R<-(R+Nnk(n-1,k-r+1)) # ,depth))
>>>>   }
>>>>   return(R)
>>>> }
>>>>
>>> You are aware that this is equivalent to:
>>>
>>> Nnk1 <- function(n, k) { prod(1:(n+k-1)) / prod(1:n) / prod(1:(k-1)) }
>> or
>>
>> Nnk2 <- function(n, k) { gamma(n+k) / gamma(n+1) / gamma(k) }
>>
>> or most easily:
>>
>> Nnk3 <- function(n, k) choose(n+k-1, n)
>>
>> Uwe Ligges
> 
> OK, I can recognise a negative binomial coefficient when I see one!
> 
> I'm wondering, though, what is the "natural" connection between
> choose(n+k-1, n) and the statement of the original question:
> 
>   What is the number of distinct non-decreasing sequences of length n
>   which can be made using integers chosen from (1:k)?
>   (repetition allowed, of course)
> 
> (The fact that this leads to a recurrence relationship which is
> satisfied by choose(n+k-1,n) is not what I mean by "natural"
> -- I'm looking for a correspondence between such a sequence, and
> a choice of n out of (n+k-1) somethings).

Colour the integers 1:k red and the integers 1:(n-1) black, and throw 
them in a hat.  Select n things out of the hat.

Put the red things in order:  that's the strictly increasing subsequence.

Put the black things in order.  Proceeding from smallest to largest, if 
you see a black i, duplicate the i'th element in the current version of 
the sequence.

For example, if k=5, n=4, you might draw red 2, 3 and black 1, 2, so 
you'd build your sequence as

2 3
2 2 3
2 2 2 3

or you might draw red 1, 4, 5 and black 2, so you'd output

1 4 4 5

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Me again, about the horrible documentation of tcltk

2007-07-06 Thread Duncan Murdoch
On 7/6/2007 7:32 AM, Alberto Monteiro wrote:
> [sorry for the previous mis-typed message... my mouse is
> playing evil tricks against me [*]]
> 
> Philippe Grosjean wrote:
>>
>> For those who are interested, I just cook a little tcltkHelp() 
>> function to ease access to the Tcl/Tk documentation under Windows. 
>> This is on the Wiki discussion of the TkCommands help page at: 
>> http://wiki.r-project.org/rwiki/doku.php?id=rdoc:tcltk:tkcommands 
>> Best,
>> 
> The help is Windows-only, isn't it? I use Windows (at work and 
> eventually at home) and Linux (at home). Maybe this is off-topic
> (it's more a bug of tcl/tk then of the tcltk R library), but this 
> tk_getOpenFile opens a nice window in Windows, but a mutilated
> window in Linux, that does not show any file information except
> filename. That's why I wanted to know if there was a way to
> improve the function call - I think there isn't.

But on Linux you can just use "the system man pages", as ?tcltk tells 
you.  (And by the way, tkgetOpenFile opens a reasonably nice window for 
me when run on a Linux system:  so this is probably a problem with your 
local installation of TCL/TK.)

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .Rprofile: Set package path for downloads

2007-07-06 Thread Duncan Murdoch
On 7/6/2007 8:04 AM, Will wrote:
> Hi,
> 
> I'd like to configure my .Rprofile so that additional packages are 
> installed and loaded from my personal package repository (let's say 
> d:/R/MyPackages/). I am working with R 2.4.1 under Windows XP.
> How do I do this?

See the repos option in ?options, or ?setRepositories.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Me again, about the horrible documentation of tcltk

2007-07-06 Thread Duncan Murdoch
On 06/07/2007 6:57 AM, Philippe Grosjean wrote:
> For those who are interested, I just cook a little tcltkHelp() function 
> to ease access to the Tcl/Tk documentation under Windows. This is on the 
> Wiki discussion of the TkCommands help page at: 
> http://wiki.r-project.org/rwiki/doku.php?id=rdoc:tcltk:tkcommands

Thanks, Philippe.  That's a useful function.

Duncan Murdoch

> Best,
> 
> Philippe Grosjean
> 
> ..<°}))><
>   ) ) ) ) )
> ( ( ( ( (Prof. Philippe Grosjean
>   ) ) ) ) )
> ( ( ( ( (Numerical Ecology of Aquatic Systems
>   ) ) ) ) )   Mons-Hainaut University, Belgium
> ( ( ( ( (
> ..........
> 
> Duncan Murdoch wrote:
>> On 06/07/2007 3:51 AM, Mike Meredith wrote:
>>> I think it would help if the tcl/tk manuals were added to the RGui Help
>>> menu. Why google when they are on your hard drive already?
>> I'd say they are too specialized for that.  There are dozens of topics 
>> that are as important as this, but a GUI menu with more than a few 
>> entries is just unwieldy.
>>
>> We do have a text reference to the help files in the ?tcltk topic.
>>
>> Duncan Murdoch
>>
>>> Cheers,  Mike
>>>
>>>
>>> Mike Prager wrote:
>>>> "Alberto Monteiro" <[EMAIL PROTECTED]> wrote:
>>>>
>>>>> How on Earth can I know what are the arguments of any of the functions of 
>>>>> the tcl/tk package? [...]
>>>> My impression is that you as supposed to look in tck/tk manuals.
>>>> For example, Googling on
>>>>
>>>> tk tck getopenfile
>>>>
>>>> pointed to this Web page:
>>>>
>>>> http://www.tcl.tk/man/tcl8.5/TkCmd/getOpenFile.htm
>>>>
>>>> Hope that helps.
>>>>
>>>> -- 
>>>> Mike Prager, NOAA, Beaufort, NC
>>>> * Opinions expressed are personal and not represented otherwise.
>>>> * Any use of tradenames does not constitute a NOAA endorsement.
>>>>
>>>> __
>>>> R-help@stat.math.ethz.ch mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Me again, about the horrible documentation of tcltk

2007-07-06 Thread Duncan Murdoch
On 06/07/2007 3:51 AM, Mike Meredith wrote:
> 
> I think it would help if the tcl/tk manuals were added to the RGui Help
> menu. Why google when they are on your hard drive already?

I'd say they are too specialized for that.  There are dozens of topics 
that are as important as this, but a GUI menu with more than a few 
entries is just unwieldy.

We do have a text reference to the help files in the ?tcltk topic.

Duncan Murdoch

> 
> Cheers,  Mike
> 
> 
> Mike Prager wrote:
>> "Alberto Monteiro" <[EMAIL PROTECTED]> wrote:
>>
>>> How on Earth can I know what are the arguments of any of the functions of 
>>> the tcl/tk package? [...]
>> My impression is that you as supposed to look in tck/tk manuals.
>> For example, Googling on
>>
>> tk tck getopenfile
>>
>> pointed to this Web page:
>>
>> http://www.tcl.tk/man/tcl8.5/TkCmd/getOpenFile.htm
>>
>> Hope that helps.
>>
>> -- 
>> Mike Prager, NOAA, Beaufort, NC
>> * Opinions expressed are personal and not represented otherwise.
>> * Any use of tradenames does not constitute a NOAA endorsement.
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Me again, about the horrible documentation of tcltk

2007-07-05 Thread Duncan Murdoch
On 05/07/2007 4:38 PM, Peter Dalgaard wrote:
> Alberto Monteiro wrote:
>> How on Earth can I know what are the arguments of any of the functions of 
>> the tcl/tk package? I tried hard to find, using all search engines 
>> available, looking deep into keywords of R, python's tkinter and tcl/tk, but 
>> nowhere I found anything remotely similar to a help.
>>
>> For example, what are the possible arguments to tkgetOpenFile?
>>
>> I know that this works:
>>
>> library(tcltk)
>> filename <- tclvalue(tkgetOpenFile(
>>   filetypes="{{Porn Files} {.jpg}} {{All files} {*}}"))
>> if (filename != "") cat("Selected file:", filename, "\n")
>>
>> but, besides filetypes, what are the other arguments to
>> tkgetOpenFile? I would like to force the files to be sorted by
>> time, with most recent files coming first (and no, the purpose is
>> not to use for porn files).
>>
>>   
> man n tk_getOpenFile
> 
> or if you are not on Unix/Linux, find it online with Google

Chances are, if Alberto is not on Unix/Linux he is on Windows (assuming 
Mac OSX counts as an *ix), and TCL and TK help files are distributed 
with R.  See RHOME/Tcl/doc.  He'll still have the problem of converting 
TCL/TK documentation conventions into their R equivalents, but I think 
you've given reasonable documentation on how to do that.

I wish we had a good way to refer to these files from the rest of the 
help system.

Duncan Murdoch


>> Alberto Monteiro
>>
>> __
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] sink() and source()

2007-07-05 Thread Duncan Murdoch
On 7/5/2007 11:35 AM, elyakhlifi mustapha wrote:
 > hello,
 > I have  a problem running a R script actually I'm using source() and 
sink() and it doesn't work
 >
 > source("T:/agents/melyakhlifi/R/essai_rep.r")
 >
 > to execute a file and the file contain
 >
 > sink("T:/agents/melyakhlifi/R/sortie.html")
 > cat("\n")
 > matrix.merge2
 > cat("\n")
 > sink()
 >
 >
 > I don't understand why when I execute just the syntax with sink() it 
work but in using source() it doesn't work
 > thanks

You don't say what is going wrong, but I suspect your problem is that 
you're not printing matrix.merge2.  Listing a variable name on a line by 
itself only causes it to be printed when you're typing at the console, 
not when it's a line in a function or a line sourced from a file.  You 
need to call print() explicitly in those cases.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Newbie creating package with compiled code

2007-07-04 Thread Duncan Murdoch
On 04/07/2007 6:43 PM, Edna Bell wrote:
> Hi R Gurus!
> 
> I'm trying to create a test package using the package.skeleton function.
> I wanted to  add some compiled code too.
> In the src library, I put together a baby subroutine, compiled it and created
> a test.dll
> 
> When I use the R cmd build, it works fine.  But I get into trouble
> with the R CMD check section.
> 
> 
> /home/Desktop/R-2.5.1/bin # ./R CMD check mypkg
> * checking for working latex ... OK
> * using log directory '/home/Desktop/R-2.5.1/bin/mypkg.Rcheck'
> * using R version 2.5.1 (2007-06-27)
> * checking for file 'mypkg/DESCRIPTION' ... OK
> * checking extension type ... Package
> * this is package 'mypkg' version '1.0'
> * checking package dependencies ... OK
> * checking if this is a source package ... OK
> * checking whether package 'mypkg' can be installed ... OK
> * checking package directory ... OK
> * checking for portable file names ... OK
> * checking for sufficient/correct file permissions ... OK
> * checking DESCRIPTION meta-information ... OK
> * checking top-level files ... OK
> * checking index information ... OK
> * checking package subdirectories ... OK
> * checking R files for non-ASCII characters ... OK
> * checking R files for syntax errors ... OK
> * checking whether the package can be loaded ... ERROR
> Error in .find.package(package, lib.loc, verbose = verbose) :
> there are no packages called 'mypkg', 'stats', 'graphics',
> 'grDevices', 'utils', 'datasets', 'methods', 'base'
> Error in library(mypkg) : .First.lib failed for 'mypkg'
> Execution halted
> 
> It looks like this package has a loading problem: see the messages for
> details.
> 
> Here is the mypkg.R file
> sss <- "/home/hodgesse/Desktop/R-2.5.1"
> .First.lib <- function(lib=sss,pkg="mypkg")
>  library.dynam("mypkg.so",pkg="mypkg",lib=sss)

That's a very strange .First.lib.  I think you'll have more success with 
a simpler one:

.First.lib <- function(libname, pkgname)
   library.dynam("mypkg", package=pkgname, lib.loc=libname)

(and sss is not needed at all).

Duncan Murdoch

> 
> 
> f <- function(x,y) x+y
> 
> g <-function(x,y) x-y
> 
> 
> Thanks for any help
> 
> Edna
> mailto: [EMAIL PROTECTED]
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] bug in closing gzfile-opened connections?

2007-07-03 Thread Duncan Murdoch
On 03/07/2007 1:37 PM, David Reiss wrote:
> Hi,
> I am making multiple calls to gzfile() via read.table(), e.g.
> 
>> x <- read.table( gzfile( "xxx.gz" ) )
> 
> After i do this many times (I haven't counted, but probably between 50 and
> 100 times) I get the error message:
> 
> Error in open.connection(file, "r") : unable to open connection
> In addition: Warning message:
> cannot open compressed file 'xxx.gz'
> 
> however, I also find that:
> 
>> showConnections()
>  description class mode text isopen can read can write
> 
> so there are no (apparently) open connections. Calling closeAllConnections()
> does not fix the problem. I have to quit and re-start R.
> I am using R 2.5.0 on a Mac (OSX 10.4.9).
> 
> Anyone know if this is a bug or a 'feature'? I see from the gzfile help
> that:
> 
>  In general functions using connections
>  will open them if they are not open, but then close them again, so
>  to leave a connection open call 'open' explicitly.

You didn't give a reproducible example, so I couldn't say.  When I 
create a gzipped version of a write.table output and run

for(i in 1:1000) read.table(gzfile(f))

in R 2.5.0 I don't see a problem.  This is on Windows, but I doubt that 
makes a difference.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] loop causes syntax error in print()

2007-07-03 Thread Duncan Murdoch
On 7/3/2007 10:23 AM, Ivan Baxter wrote:
> 
> Duncan Murdoch wrote:
>> On 7/3/2007 1:59 AM, Ivan Baxter wrote:
>>> I am having trouble printing a table out to the GUI display when the 
>>> table is created and printed within a loop.
>>>
>>> I get a "Error: syntax error message"
>>>
>>> If I comment out the print statement, the loop runs fine and I can 
>>> print out the last iteration of the table.
>>
>> You should simplify your loop until it's something you can post for us 
>> to try.  Chances are you'll notice the error when you do that, but if 
>> not, someone else will be able to tell you what's going on.
>>
>> Without a reproducible example, it's more or less hopeless.
>>
>> Duncan Murdoch
> Right- well I did as you suggested and seem to have fixed the problem.
> 
> The problem appeared to be that some carriage returns were not 
> registering in the Mac Os X R editor. So even though it looked like it 
> was on a new line, it wasn't. It wasn't a line wrap issue, these were 
> actually returns that I had hit that just weren't registering. I had one 
> chunk of code which showed what I thought was the problem when R 
> crashed. When I opened up the script again after restarting, the problem 
> disappeared, so somehow the returns started to be seen.
> 

If you can reproduce this in the future, it might be worth trying to use 
cut and paste to save a record of the offending text, and sending it to 
the Mac GUI maintainers.  I would guess there's some special code that 
is shown by the editor as a newline but seen by the parser as just 
another character.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] loop causes syntax error in print()

2007-07-03 Thread Duncan Murdoch
On 7/3/2007 1:59 AM, Ivan Baxter wrote:
> I am having trouble printing a table out to the GUI display when the 
> table is created and printed within a loop.
> 
> I get a "Error: syntax error message"
> 
> If I comment out the print statement, the loop runs fine and I can print 
> out the last iteration of the table.

You should simplify your loop until it's something you can post for us 
to try.  Chances are you'll notice the error when you do that, but if 
not, someone else will be able to tell you what's going on.

Without a reproducible example, it's more or less hopeless.

Duncan Murdoch

> 
> ...[multiple loops and calculations ending with.]...
> 
> + print(paste(mutType,"sim",sim,"hmm",hmm))  
> + # print(acctab[,10:15])
> +
> + nummod <- nummod +1
> + }  #end hmmMats loop
> + }  #end tmats loop   
> + }  #end mut type loop
> [1] "dup sim Imod hmm Jmod"
> 
>  > print(acctab[,10:15])
> hitrate falsepos   multrate  avghit avgmiss avgfalsepos
> 1 0.0001NaN NaN   2  NA
> 2 1.0000 0.5.33 NaN  NA
> 3 0.000  NaNNaN NaN   9  NA
> 4 0.7780 0.   15.571429  11  NA
> 5 1.0000 0.   24.08 NaN  NA
> 6 1.0000 0.07692308   64.538462 NaN  NA
> 7 1.0000 0.39207048 1088.454846 NaN  NA
> 
> you can see that
> a) the print statement above it works
> b) the print command works with this table
> 
> but if I uncomment it and try to run the loops again.
> 
> + print(paste(mutType,"sim",sim,"hmm",hmm)) 
>   print(acctab[,10:15])
> Error: syntax error
>  >
>  >
>  > nummod <- nummod +1
>  > }  #end hmmMats loop
> Error: syntax error
>  > }  #end tmats loop   
> Error: syntax error
>  > }  #end mut type loop
> Error: syntax error
> 
> 
> I have tried print.data.frame, but that doesn't work either
> 
> 
> Any suggestions would be appreciated  (session info below)
> 
> 
> Ivan
> 
> 
>  > sessionInfo()
> R version 2.5.1 (2007-06-27)
> i386-apple-darwin8.9.1
> 
> locale:
> C
> 
> attached base packages:
> [1] "stats" "graphics"  "grDevices" "utils" "datasets"  
> "methods"   "base"  
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave bug? when writing figures / deleting variable in chunk

2007-06-27 Thread Duncan Murdoch
On 27/06/2007 9:06 PM, D G Rossiter wrote:
> I have found a quite strange (to me) behaviour in Sweave. It only  
> occurs in the following situation:
> 
> 1. define a variable in one chunk
> 2. use it within a subsequent figure-generating chunk
> 3. delete it at the end of that same chunk
> Then the Sweave driver chokes, not finding the variable name when  
> generating the figure

By default, Sweave runs figure chunks twice (once for pdf, once for 
eps).  They shouldn't change the environment they need to run in.  Not 
sure where this is documented, but it's well known by people who've been 
bitten by it.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] surprising difference in log()

2007-06-26 Thread Duncan Murdoch
On 6/26/2007 10:20 AM, Mike Lawrence wrote:
> According to the description of floor(), the latter result is the  
> correct one:
> 
> 'floor takes a single numeric argument x and returns a numeric vector  
> containing the largest integers *not greater than* the corresponding  
> elements of x.' (emphasis added)
> 
> floor(3) == 2
>  >True

3 is not greater than 3, but it is greater than 2, so the result you 
quote above is wrong.  You should see

> floor(3)
  [1] 3

 > floor(3) == 2
[1] FALSE

Do you really see the result you posted?

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] a string to enviroment or function

2007-06-25 Thread Duncan Murdoch
On 25/06/2007 4:19 PM, Weiwei Shi wrote:
> then how to do this
> 
> f1 <- function(mylab){
>   library(mylab)
>   ...
> }
> 
> it seems that if you call
> library("hgu133a") # which is file
> # but
> library(mylab) # even you pass "hgu133a" as parameter, it still
> complains about "mylab" does not exist. It seems that it consider
> mylab as package instead of its value.

One of the examples in ?library shows how to do what you want.

pkg <- "splines"
library(pkg, character.only = TRUE)

Duncan Murdoch

>>> Weiwei Shi, Ph.D
>>> Research Scientist
>>> GeneGO, Inc.

P.S. If you think this was helpful, one of the ways to contribute back 
to the R project would be to ask your employer to become an 
institutional member:  see

http://www.r-project.org/foundation/membership.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Setting up a blank table with column names in the hard drive

2007-06-24 Thread Duncan Murdoch
On 23/06/2007 7:51 PM, Yuchen Luo wrote:
> Dear Professor Murdoch.
> Thank you so much! Your help is highly appreciated!

Please send replies to the mailing list.
> 
> When I use the following commands, there is a blank cell before title "name"
> in the resulting csv (excel) file. I am wondering how to get rid of it? I
> want to get rid of it because when I write subsequent rows to the file, the
> "name" part start from the beginning which is not aligned with the first
> line of the column titles.

That's a place holder for the row names.  If you don't want it, specify 
row.names=FALSE (and do the same when you write subsequent lines).

Duncan Murdoch

> 
> " blank <- data.frame(name=character(0), wife=character(0),
> no.children=numeric(0))
> write.csv(blank, 'file.csv')"
> 
> Thank you for your help again and your time is highly appreciated!
> 
> Best Wishes
> Yuchen Luo
> I
> 
> 
> On 6/23/07, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
>> Yuchen Luo wrote:
>>> Dear Friends.
>>> Greetings!
>>>
>>> This should be a very common operation and I believe there should be a
>> nice
>>> way in R to handle it.  I couldn't find it in the manual or by searching
>> on
>>> line. I am wondering if I could ask for some help in this community.
>>>
>>>
>>>
>>> I am trying to record the results of my program to a csv file in the
>> hard
>>> drive so as to save memory space and also to read the results in excel
>> after
>>> running the program.  Every loop of my program will result in a list
>> with
>>> element belonging to different class. For example, things like
>>>
>>>
>>>
>>> a1 <- list(name="Fred", wife="Mary", no.children=3)
>>> a2 <- list(name="Tom", wife="Joy", no.children=9)
>>> a3 <- list(name="Paul", wife="Alic", no.children=5)
>>>
>>>
>>>
>>> I want the columns to have titles, in the example above, I want to see
>> the
>>> title "name", "wife" and "no.children" in the excel file.
>>>
>>>
>>>
>>> To set up the table in the csv file, I need to add at least one row in
>> the
>>> table up front. How ever, I do not have the first loop of the program
>>> completed yet at that time. If I add a row that is meaningless, how may
>> I
>>> delete it after all the loops are completed and all the meaningful rows
>> are
>>> added to the table?
>>>
>>>
>> I'd use data frames rather than plain lists for the results, so
>> write.csv will work.
>>
>> Create a data frame with 0 rows, and write it out:  this will give you
>> your header line.
>>
>> e.g.
>>
>>
>>
>> Now you can rbind new lines onto the data frame as you calculate new
>> records and rewrite the whole thing, or just append them to the file
>> with append=TRUE and writing with col.names=FALSE.
>>
>> Duncan Murdoch
>>
>>
>

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Setting up a blank table with column names in the hard drive

2007-06-23 Thread Duncan Murdoch
Yuchen Luo wrote:
> Dear Friends.
> Greetings!
>
> This should be a very common operation and I believe there should be a nice
> way in R to handle it.  I couldn't find it in the manual or by searching on
> line. I am wondering if I could ask for some help in this community.
>
>
>
> I am trying to record the results of my program to a csv file in the hard
> drive so as to save memory space and also to read the results in excel after
> running the program.  Every loop of my program will result in a list with
> element belonging to different class. For example, things like
>
>
>
> a1 <- list(name="Fred", wife="Mary", no.children=3)
> a2 <- list(name="Tom", wife="Joy", no.children=9)
> a3 <- list(name="Paul", wife="Alic", no.children=5)
>
>
>
> I want the columns to have titles, in the example above, I want to see the
> title "name", "wife" and "no.children" in the excel file.
>
>
>
> To set up the table in the csv file, I need to add at least one row in the
> table up front. How ever, I do not have the first loop of the program
> completed yet at that time. If I add a row that is meaningless, how may I
> delete it after all the loops are completed and all the meaningful rows are
> added to the table?
>
>   
I'd use data frames rather than plain lists for the results, so 
write.csv will work.

Create a data frame with 0 rows, and write it out:  this will give you 
your header line.

e.g.

blank <- data.frame(name=character(0), wife=character(0), 
no.children=numeric(0))
write.csv(blank, 'file.csv')

Now you can rbind new lines onto the data frame as you calculate new 
records and rewrite the whole thing, or just append them to the file 
with append=TRUE and writing with col.names=FALSE.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] speed issues / pros & cons: dataframe vs. matrix

2007-06-22 Thread Duncan Murdoch
On 22/06/2007 6:21 PM, Thomas Pujol wrote:
> I've read that certain operations performed on a matrix (e.g. ribind, cbind) 
> are often much faster compared to operations performed on a data frame.
> 
> Other then the "bind functions", what are the main operations that are 
> significantly faster on a a matrix?

Indexing (e.g. x[1,3]) is much faster on a matrix.
> 
> I know that data frames allow for columnnames and rownames, and that each 
> column in a data frame can have different data types.  Are there any other 
> advantages of storing data in a a dataframe rather then a matrix?

Data frames are lists, so you can use things like df$columnname, 
with(df, expression), attach(df), etc.  Data frame columns have names, 
but matrices don't necessarily.

I'd generally use data frames in any situation where the rows are cases 
and the columns are characteristics, until I found they were too slow: 
and then I'd consider temporary conversion to a matrix to speed things 
up.  As Knuth said, premature optimization is the root of all evil.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Matrix library, CHOLMOD error: problem too large

2007-06-22 Thread Duncan Murdoch
On 6/22/2007 1:26 PM, Jose Quesada wrote:
> I have a pretty large sparse matrix of integers:
>> dim(tasa)
> [1] 91650 37651
> 
> I need to add one to it in order to take logs, but I'm getting the  
> following error:
> 
>> tasa  = log(tasa + 1)
> CHOLMOD error: problem too large
> Error in asMethod(object) : Cholmod error `problem too large'
> 
> I have 2 Gb of RAM, and the current workspace is barely 300mb.
> Is there any workaround to this? Anyone has any experience with this error?
>

If tasa is sparse, then tasa+1 will not be sparse, so that's likely your 
problem.  You might have better luck with

log1p(tasa)

if the authors of the Matrix package have written a method for log1p(); 
if not, you'll probably have to do it yourself.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] what is "better" when combining data frames? merge vs. rbind & cbind

2007-06-22 Thread Duncan Murdoch
On 21/06/2007 3:36 PM, Thomas Pujol wrote:
> I often need to "combine" data frames, sometimes "vertically" and other times 
> "horizontally".
> 
> When it "better" to use merge? When is it better to use rbind or cbind?
> 
> Are there clear pros and cons of each approach?

If rbind or cbind work, use them.  They are much simpler, but much less 
flexible.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding exponents (superscript format) to a plot

2007-06-21 Thread Duncan Murdoch
On 21/06/2007 7:39 PM, Judith Flores wrote:
 > Hi,
 >
 >I need to add exponents to a label in one of the
 > axes of a plot, how can I do this?

See ?plotmath.  For example,

plot(1,2, xlab=expression(x^2), ylab=expression(exp(-x^2/2)))

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using the object of character data type as the name of the slot

2007-06-21 Thread Duncan Murdoch
On 21/06/2007 4:07 PM, Alex Tsoi wrote:
> Dear all,
> 
> I have a character string object:
> 
>> chara
> [1]  "The name of first slot"
> 
> and a list object:
> 
>> class( try1)
> [1] "list"
> 
> 
> what I want to do is to use the chara as a slot's name of "try1".
> 
> Of  course I could do it like:
> 
>> try1$"The name of first slot"  <- matrix("", 3, 4)
> 
> to create a slot of 3x4 matrix with the name "The name of first slot"
> 
> However, I would like to know how could I utilize the object chara , and to
> use the characters it contains as the name of the slot of try1.

You can use

slot(try1, chara) <- matrix("", 3, 4)

as long as the slot name contained in chara really is a slot.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] non permanent change of vector values

2007-06-20 Thread Duncan Murdoch
On 20/06/2007 6:46 AM, Federico Calboli wrote:
> Hi All,
> 
> I have the following problem: I have a vector
> 
> x = rep(0,15)
> x[1:2] = 1
> x
>   [1] 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> I need to be able to call that vector 'x' so that if condition 'A' is true, 
> only 
> the first value is kept 'as is' and all the others are put to 0
> 
> if(A == T)
> 
> function(x) with x returning 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> and if 'A' is false the second value is kept 'as is' and all the others are 
> put to 0
> 
> if(A == F)
> 
> function(x) with x returning 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> BUT, and that's the rub, I need x to changed in a *non permanent* way, so 
> that 
> at the end x is still
> 
> x
>   [1] 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
> 
> (that is because condition 'A' might be called again and could be different 
> in 
> it's T/F state from previous calls).

Simply make a function that does what you want:

modifyx <- function(x, A) {
   if (A) x[-1] <- 0
   else x[-2] <- 0
   x
}

then call your function by passing modifyx(x, A) instead of just x.

You don't need to put A or x in the argument list of the function, but 
it probably makes sense to do so.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   3   4   5   6   7   8   9   10   >