Re: [R] Trouble with plm in Ubuntu 9

2010-03-10 Thread Jyotirmoy Bhattacharya
The example works fine for me. I am using the same version of R (2.9.2) from
the Ubuntu 9.10 AMD-64 repositories and plm version 1.2-3 downloaded from
CRAN.

One point. The plm help example loads the Produc dataset from the package
plm and not the package Ecdat. Though I can get the example to run with
Ecdat 0.1-5 as well.

Jyotirmoy Bhattacharya

On Thu, Mar 11, 2010 at 4:30 AM, Stephen J. Barr stephenjb...@gmail.comwrote:

 Hello,

 Apologies in advance if this is a stupid question. I am running R on Ubuntu
 9.

 R version 2.9.2 (2009-08-24)

 I am trying to work with plm. I think the library is installed, as I can do

  library(plm)
 Loading required package: kinship
 Loading required package: survival
 Loading required package: splines
 Loading required package: nlme
 Loading required package: lattice
 [1] kinship is loaded
 Loading required package: Formula
 Loading required package: MASS
 Loading required package: sandwich
 Loading required package: zoo

 Attaching package: 'zoo'


 The following object(s) are masked from package:base :

  as.Date.numeric

 

 which seems reasonable. However, it fails running the included example in
 the help.

  data(Produc, package=Ecdat)
   zz - plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp, data=Produc,
 index=c(state,year))
 Error in do.call(~, list(firstpart, as.name(i))) :
  object 'firstpart' not found
 In addition: Warning messages:
 1: In if (length(formula) == 2) formula - expand.formula(formula) :
  the condition has length  1 and only the first element will be used
 2: In if (length(formula) == 1) part = first :
  the condition has length  1 and only the first element will be used
 3: In if (length(formula) == 2) part = both :
  the condition has length  1 and only the first element will be used
 4: In if (length(x) == 1) { :
  the condition has length  1 and only the first element will be used
 5: In if (length(x) == 2) { :
  the condition has length  1 and only the first element will be used

 At first I thought it was my code that was causing the error, but if it is
 failing on the example from the ?plm page, then I figured I should start
 there. Any suggestions?

 Thank you,
 -stephen

[[alternative HTML version deleted]]

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] dot-dot-dot as an actual argument

2010-02-19 Thread Jyotirmoy Bhattacharya
I could not find any documentation of how dot-dot-dot works when used
as an argument in a function call (rather than as a formal argument in
a definition). I would appreciate some references to the rules
governing situations like:

f1-function(x,y,...){
  print(x)
}

f2-function(...){
  f1(...)
}

f2(1,2,3)

In the call above how are the three numbers bound to the individual
formal arguments x and y of f1 rather than f1 being called with a
single pairlist, which is what the documentation says ... is.

And while the example above succeeds, why does the following fail,

library(lattice)
f.barchart - function(...) {
    barchart(...)
}

x - data.frame(a = c(1,1,2,2), b = c(1,2,3,4), d = c(1,2,2,1))
print(f.barchart(a ~ b, data = x, groups = d))

This gives the error:
Error in eval(expr, envir, enclos) :
  ..3 used in an incorrect context, no ... to look in

Jyotirmoy Bhattacharya

__
R-help@r-project.org 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] unexpected results with higher-order functions and lapply

2010-02-14 Thread Jyotirmoy Bhattacharya
I want to use lapply and a function returning a function in order to build a
list of functions.

 genr1 - function(k) {function() {k}}
 l1 - lapply(1:2,genr1)
 l1[[1]]()
[1] 2

This was unexpected. I had expected the answer to be 1, since that is the
value k should be bound to when genr1 is applied to the first element of
1:2.

By itself genr1 seems to work fine.
 genr1(5)()
[1] 5

I defined a slightly different higher-order function:
 genr2 - function(k) {k;function() {k}}
 l2 - lapply(1:2,genr2)
 l2[[1]]()
[1] 1

This gives the answer I expected.

Now I am confused. The function returned by genr2 is exactly the same
function that was being returned by genr1. Why should evaluating k make a
difference?

I am using R 2.9.2 on Ubuntu Linux.

Jyotirmoy Bhattacharya

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.