[Rd] Method from package dependency is not updated due to lazy load?

2016-02-10 Thread Renaud Gaujoux
Hi,

not sure this is a bug or just an unavoidable undesirable side-effect -- or
just me that does not do the right thing.

Consider the code and output below. It creates 2 packages:
  * pkgA
  * pkgB that creates a method for a generic defined in pkgA

Changes in a method for the generic in pkgA (after re-installing pkgA) are
not reflected in pkgB, unless pkgB is re-installed against the new version
of pkgA.
I understand this may be linked to lazy-loading, which somehow keeps the
old method version.
More worrying is the fact that calling pkgA::genericA() in  .GlobalEnv
still calls the old version.

I guess this is due to lazy-load caching the method definition, but is this
normal/known behaviour?

This means that all the packages that depend on pkgA must be re-installed,
even after small internal changes that do not affect the interface or
behavior of the exported generic, e.g., internal functions with new
required arguments used in the imported generic (which is the error that
got me looking into this).

Updating reverse-dependencies when installing pkgA could solve the issue
(default with message, and optionally disabled). At minimum, a warning when
loading pkgB could notify the user that there could be issues due to
version discrepancy.

Thank you.

Bests,
Renaud

## Code

library(devtools)
unlink('test', recursive = TRUE)
dir.create('test/lib', recursive = TRUE)
# create packages
createA <- function(version){
  dir.create(file.path('test', version), recursive = TRUE)
  pdir <- file.path('test', version, 'pkgA')
  create(pdir, list(Depends = 'methods'), rstudio = FALSE)
  cat(sprintf("
  setGeneric('genericA', function(x) standardGeneric('genericA'))
  setMethod('genericA', 'missing', function(x) 'A-%s')", version), file =
file.path(pdir, 'R/function.R'))
}
createA('v1')
createA('v2')
# package B imports A
create('test/pkgB', list(Imports = 'pkgA', Depends = 'methods'), rstudio =
FALSE)
cat('import(pkgA)', file = 'test/pkgB/NAMESPACE', append = TRUE)
cat("
callA <- function() genericA()
setGeneric('genericA', package = 'pkgA')
setMethod('genericA', 'character', function(x) genericA())
", file = 'test/pkgB/R/function.R')

# install packages
install.packages('test/v1/pkgA', lib = 'test/lib', repos = NULL, quiet =
TRUE)
install.packages('test/pkgB', lib = 'test/lib', repos = NULL, quiet = TRUE)
# this returns A-v1
system("Rscript -e \"library(pkgA, lib = 'test/lib'); genericA()\"")
system("Rscript -e \"library(pkgB, lib = 'test/lib'); callA();
pkgA::genericA()\"")

# install pkgA version 2
install.packages('test/v2/pkgA', lib = 'test/lib', repos = NULL, quiet =
TRUE)
# this returns A-v2
system("Rscript -e \"library(pkgA, lib = 'test/lib'); genericA()\"")
# this still returns A-v1
system("Rscript -e \"library(pkgB, lib = 'test/lib'); callA();
pkgA::genericA()\"")

# re-install pkgB
install.packages('test/pkgB', lib = 'test/lib', repos = NULL, quiet = TRUE)
# this now returns A-v2
system("Rscript -e \"library(pkgB, lib = 'test/lib'); callA();
pkgA::genericA()\"")


### Output

> library(devtools)> unlink('test', recursive = TRUE)> dir.create('test/lib', 
> recursive = TRUE)> # create packages> createA <- function(version){+   
> dir.create(file.path('test', version), recursive = TRUE)+   pdir <- 
> file.path('test', version, 'pkgA')+   create(pdir, list(Depends = 'methods'), 
> rstudio = FALSE)+   cat(sprintf("+   setGeneric('genericA', function(x) 
> standardGeneric('genericA'))+   setMethod('genericA', 'missing', function(x) 
> 'A-%s')", version), file = file.path(pdir, 'R/function.R'))+ }> 
> createA('v1')Creating package 'pkgA' in '/home/renaud/tmp/r-devel/test/v1'
No DESCRIPTION found. Creating with values:


Package: pkgA
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.l...@example.com",
role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: methods
License: What license is it under?
LazyData: true> createA('v2')Creating package 'pkgA' in
'/home/renaud/tmp/r-devel/test/v2'
No DESCRIPTION found. Creating with values:


Package: pkgA
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.l...@example.com",
role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: methods
License: What license is it under?
LazyData: true> # package B imports A> create('test/pkgB',
list(Imports = 'pkgA', Depends = 'methods'), rstudio = FALSE)Creating
package 'pkgB' in '/home/renaud/tmp/r-devel/test'
No DESCRIPTION found. Creating with values:


Package: pkgB
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.l...@example.com",
role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: methods
License: What license is it under?
LazyData: true
Imports: pkgA> cat('import(pkgA)', file = 'test/pkgB/NAMESPACE',
append = TRUE)> cat("+ call

Re: [Rd] problem plotting "ts" in a data.frame

2016-02-10 Thread Martyn Plummer
On Tue, 2016-02-09 at 16:56 -0600, Spencer Graves wrote:
> Hello:
> 
> 
>I'm having trouble plotting an object of class "ts" that is in a 
> data.frame.  I can do it with(data.frame, plot(...)) but not with 
> plot(..., data.frame);  see the example below.

The plot function is generic so the actual function call depends on what
arguments you give it: plot(y.ts) calls the plot.ts method from the
stats package, whereas plot(y.ts ~ x) calls the plot.formula method from
the graphics package. Only the plot.formula method has a data argument.

What happens when you call plot(y1~x1, data=XY) is that first
plot.formula is called and then this calls plot.ts with two arguments
(XY$x1 and XY$y1) that are expected to be compatible time series.
However, they are not. In fact x1 is numeric and when coerced to a time
series it has no time points in common with y1 (which starts at time
t=5). Hence the warning about non-intersecting series.

Since non-overlapping series seems to be fatal in this context it might
be a good idea to give an error at this point. Otherwise I think the
function is behaving correctly.

Martyn

>This work around gets me past this problem.  However, I thought 
> the R Core team might want to know about this if they don't already.
> 
> 
>Thanks for all your work in making R and CRAN the great tools 
> that they are -- and I apologize for wasting your time if you are 
> already familiar with this.
> 
> 
>Spencer Graves
> 
> 
>  > y.ts <- ts(2:4, 5)
>  > XY <- data.frame(x1=6:8, y1=y.ts)
>  > plot(y1~x1, XY)
> Error in plot.window(...) : need finite 'xlim' values
> In addition: Warning messages:
> 1: In .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = 
> FALSE) :
>non-intersecting series
> 2: In min(x) : no non-missing arguments to min; returning Inf
> 3: In max(x) : no non-missing arguments to max; returning -Inf
> 4: In min(x) : no non-missing arguments to min; returning Inf
> 5: In max(x) : no non-missing arguments to max; returning -Inf
>  > plot(y1, XY)
> Error in plot(y1, XY) : object 'y1' not found
>  > with(XY, plot(y1))
>  > sessionInfo()
> R version 3.2.3 (2015-12-10)
> Platform: x86_64-apple-darwin13.4.0 (64-bit)
> Running under: OS X 10.11.2 (El Capitan)
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
> 
> loaded via a namespace (and not attached):
> [1] tools_3.2.3
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

---
This message and its attachments are strictly confidenti...{{dropped:8}}

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


Re: [Rd] problem plotting "ts" in a data.frame

2016-02-10 Thread Spencer Graves



On 2/10/2016 9:43 AM, Martyn Plummer wrote:

On Tue, 2016-02-09 at 16:56 -0600, Spencer Graves wrote:

Hello:


I'm having trouble plotting an object of class "ts" that is in a
data.frame.  I can do it with(data.frame, plot(...)) but not with
plot(..., data.frame);  see the example below.

The plot function is generic so the actual function call depends on what
arguments you give it: plot(y.ts) calls the plot.ts method from the
stats package, whereas plot(y.ts ~ x) calls the plot.formula method from
the graphics package. Only the plot.formula method has a data argument.

What happens when you call plot(y1~x1, data=XY) is that first
plot.formula is called and then this calls plot.ts with two arguments
(XY$x1 and XY$y1) that are expected to be compatible time series.
However, they are not. In fact x1 is numeric and when coerced to a time
series it has no time points in common with y1 (which starts at time
t=5). Hence the warning about non-intersecting series.

Since non-overlapping series seems to be fatal in this context it might
be a good idea to give an error at this point. Otherwise I think the
function is behaving correctly.

Martyn


Hi, Martyn:


  Thanks for the reply.  I think it's interesting that "plot(x1~y1, 
XY)" works roughly as I would have expected, as does 
"plot(as.numeric(y1)~x1, XY)".  However, "plot(y1~x1, XY)" stops with 
"need finite 'xlim' values" after arriving at "plot.window".  I found 
that quite cryptic.



  In any case, that's for your contributions to R and for 
responding to my question.



  Spencer


This work around gets me past this problem.  However, I thought
the R Core team might want to know about this if they don't already.


Thanks for all your work in making R and CRAN the great tools
that they are -- and I apologize for wasting your time if you are
already familiar with this.


Spencer Graves


  > y.ts <- ts(2:4, 5)
  > XY <- data.frame(x1=6:8, y1=y.ts)
  > plot(y1~x1, XY)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union =
FALSE) :
non-intersecting series
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
4: In min(x) : no non-missing arguments to min; returning Inf
5: In max(x) : no non-missing arguments to max; returning -Inf
  > plot(y1, XY)
Error in plot(y1, XY) : object 'y1' not found
  > with(XY, plot(y1))
  > sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.2 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] tools_3.2.3

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

---
This message and its attachments are strictly confiden...{{dropped:9}}


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