Re: [Rd] if(--as-cran)?

2012-09-03 Thread Henrik Bengtsson
Hi, see thread "[Rd] Proposal: Mechanism for controlling the amount of
testing 'R CMD check' performs" on April 8, 2012:

  https://stat.ethz.ch/pipermail/r-devel/2012-April/063809.html

/Henrik


On Sun, Sep 2, 2012 at 10:43 PM, Spencer Graves
 wrote:
> Hello, All:
>
>
>   The fda package has tests that run too long for CRAN's current rules.
> I'd like to wrap some examples in a construct like the following:
>
>
> if(!CRAN()){
> ...
> }
>
>
>   I tried the following:
>
>
> CRAN <- function(x='_R_CHECK_CRAN_INCOMING_'){
> x. <- Sys.getenv(x)
> xl <- as.logical(x.)
> notCRAN <- is.na(xl) || xl
> #
> return(!notCRAN)
> }
>
>
>   The companion help page included the following example:
>
>
> if(CRAN()){
>   stop('CRAN')
> } else {
>   stop('NOT CRAN')
> }
>
>
>   This reported "NOT CRAN" even with "R CMD check --as-cran".
>
>
>   Suggestions?
>   Thanks,
>   Spencer
>
>> sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
>
> other attached packages:
> [1] sos_1.3-5  brew_1.0-6
>
> loaded via a namespace (and not attached):
> [1] tools_2.15.1
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

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


[Rd] Typo (?) in 'aggregate.formula'

2012-09-03 Thread Suharto Anggono Suharto Anggono
In the code for 'aggregate.formula', there is
if (as.character(formula[[2L]] == "."))
I believe that it is meant to be
if (as.character(formula[[2L]]) == ".")

However,
if (as.character(formula[[2L]] == "."))
gives the expected result.
Tracing:
- formula[[2L]] == "."
is equivalent to
as.character(formula[[2L]]) == "."
>From the help page for '==' (Comparison), "Language objects such as symbols 
>and calls are deparsed to character strings before comparison."
- By applying 'as.character', the TRUE/FALSE result of
formula[[2L]] == "."
is converted to character, becomes "TRUE"/"FALSE".
- Then, for 'if', it is implicitly converted back to logical.


> sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

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


I see that, in R 2.15.1, the code for 'aggregate.formula' is still the same.

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


Re: [Rd] Typo (?) in 'aggregate.formula'

2012-09-03 Thread peter dalgaard
This (and more) was fixed in r-devel back in May. Did you actually get bitten 
by this? (The code has been there for years, so it hasn't been slated for 
R-patched.)

-pd 

On Sep 3, 2012, at 11:06 , Suharto Anggono Suharto Anggono wrote:

> In the code for 'aggregate.formula', there is
> if (as.character(formula[[2L]] == "."))
> I believe that it is meant to be
> if (as.character(formula[[2L]]) == ".")
> 
> However,
> if (as.character(formula[[2L]] == "."))
> gives the expected result.
> Tracing:
> - formula[[2L]] == "."
> is equivalent to
> as.character(formula[[2L]]) == "."
> From the help page for '==' (Comparison), "Language objects such as symbols 
> and calls are deparsed to character strings before comparison."
> - By applying 'as.character', the TRUE/FALSE result of
> formula[[2L]] == "."
> is converted to character, becomes "TRUE"/"FALSE".
> - Then, for 'if', it is implicitly converted back to logical.
> 
> 
>> sessionInfo()
> R version 2.14.2 (2012-02-29)
> Platform: i386-pc-mingw32/i386 (32-bit)
> 
> locale:
> [1] LC_COLLATE=English_United States.1252 
> [2] LC_CTYPE=English_United States.1252   
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C  
> [5] LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base 
> 
> 
> I see that, in R 2.15.1, the code for 'aggregate.formula' is still the same.
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [Rd] Typo (?) in 'aggregate.formula'

2012-09-03 Thread Suharto Anggono Suharto Anggono
No, I didn't actually get bitten by this. I used 'aggregate.formula' only 
recently. I saw this when trying to know how 'aggregate.formula' worked, 
especially in accepting dot (.) in left-hand side of formula.
Thanks for the fix.

--- On Mon, 3/9/12, peter dalgaard  wrote:

> From: peter dalgaard 
> Subject: Re: [Rd] Typo (?) in 'aggregate.formula'
> To: "Suharto Anggono Suharto Anggono" 
> Cc: R-devel@r-project.org
> Date: Monday, 3 September, 2012, 4:43 PM
> This (and more) was fixed in r-devel
> back in May. Did you actually get bitten by this? (The code
> has been there for years, so it hasn't been slated for
> R-patched.)
> 
> -pd 
> 
> On Sep 3, 2012, at 11:06 , Suharto Anggono Suharto Anggono
> wrote:
> 
> > In the code for 'aggregate.formula', there is
> > if (as.character(formula[[2L]] == "."))
> > I believe that it is meant to be
> > if (as.character(formula[[2L]]) == ".")
> > 
> > However,
> > if (as.character(formula[[2L]] == "."))
> > gives the expected result.
> > Tracing:
> > - formula[[2L]] == "."
> > is equivalent to
> > as.character(formula[[2L]]) == "."
> > From the help page for '==' (Comparison), "Language
> objects such as symbols and calls are deparsed to character
> strings before comparison."
> > - By applying 'as.character', the TRUE/FALSE result of
> > formula[[2L]] == "."
> > is converted to character, becomes "TRUE"/"FALSE".
> > - Then, for 'if', it is implicitly converted back to
> logical.
> > 
> > 
> >> sessionInfo()
> > R version 2.14.2 (2012-02-29)
> > Platform: i386-pc-mingw32/i386 (32-bit)
> > 
> > locale:
> > [1] LC_COLLATE=English_United States.1252 
> > [2] LC_CTYPE=English_United
> States.1252   
> > [3] LC_MONETARY=English_United States.1252
> > [4] LC_NUMERIC=C         
>                 
> > [5] LC_TIME=English_United States.1252    
> > 
> > attached base packages:
> > [1] stats     graphics 
> grDevices utils     datasets 
> methods   base     
> > 
> > 
> > I see that, in R 2.15.1, the code for
> 'aggregate.formula' is still the same.
> > 
> > __
> > R-devel@r-project.org
> mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> -- 
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk 
> Priv: pda...@gmail.com
> 
>

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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Duncan Murdoch

On 12-09-03 1:43 AM, Spencer Graves wrote:

Hello, All:


The fda package has tests that run too long for CRAN's current
rules.  I'd like to wrap some examples in a construct like the following:


if(!CRAN()){
...
}


I tried the following:


CRAN <- function(x='_R_CHECK_CRAN_INCOMING_'){
  x. <- Sys.getenv(x)
  xl <- as.logical(x.)
  notCRAN <- is.na(xl) || xl
#
  return(!notCRAN)
}


The companion help page included the following example:


if(CRAN()){
stop('CRAN')
} else {
stop('NOT CRAN')
}


This reported "NOT CRAN" even with "R CMD check --as-cran".


There's no user-visible setting for --as-cran, because it just sets a 
number of other options.  You could query one of those.  The settings 
that are visible are


_R_CHECK_TIMINGS_  (which seems most relevant to you)
_R_CHECK_INSTALL_DEPENDS_
_R_CHECK_NO_RECOMMENDED_
_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_

So I'd check the value in _R_CHECK_TIMINGS_, or maybe just its existence.

Duncan Murdoch

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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Dirk Eddelbuettel

On 3 September 2012 at 00:49, Henrik Bengtsson wrote:
| Hi, see thread "[Rd] Proposal: Mechanism for controlling the amount of
| testing 'R CMD check' performs" on April 8, 2012:
| 
|   https://stat.ethz.ch/pipermail/r-devel/2012-April/063809.html

Good proposal, somehow I missed that at the time.  Something like this ought
be to implemented in R proper.

In Rcpp, I am now using a similar environment-variable-based approach, and it
doesn't scale particularly well if every (large) package does its own thing.

Dirk
 
| /Henrik

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Martin Maechler
> Dirk Eddelbuettel 
> on Mon, 3 Sep 2012 09:34:06 -0500 writes:

> On 3 September 2012 at 00:49, Henrik Bengtsson wrote:
> | Hi, see thread "[Rd] Proposal: Mechanism for controlling the amount of
> | testing 'R CMD check' performs" on April 8, 2012:
> | 
> |   https://stat.ethz.ch/pipermail/r-devel/2012-April/063809.html

> Good proposal, somehow I missed that at the time.
> Something like this ought be to implemented in R proper.

I agree but the CRAN maintainers have to agree too.


> In Rcpp, I am now using a similar
> environment-variable-based approach, and it doesn't scale
> particularly well if every (large) package does its own thing.

yes, my packages do their own thing too, now, e.g., Matrix
(not yet released):

doExtras <- interactive() || nzchar(Sys.getenv("R_MATRIX_CHECK_EXTRA")) ||
identical("true", unname(Sys.getenv("R_PKG_CHECKING_doExtras")))

and then I use  if(doExtras) {  }
but I agree with Henrik that it would make sense to have more
than just two levels for the amount of testing, not just for CRAN.

An additional, slightly more interesting feature request that
you may also want in these cases, is the following:
Assume, that we have a function testingLevel()
and the following code should only be run, if the testing level
is 2 or higher

if(testingLevel() > 2) {
 ...1
 ...2
 
 
 ...n
}

Now what we all really wanted was that the  code
ran just as in toplevel.
While I think that's almost impossible,
as the .1 to .n must first be parsed all, and then
evaluated (which is already different from top level),
I would at least want that  the auto-printing worked like in
toplevel, so I don't have to write a  print(.) around every
..i that would autoprint if in toplevel, and of course does
*not* autoprint inside if(.) { .. }.

Martin Maechler, ETH Zurich

> Dirk
 
> | /Henrik

> -- 
> Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


[Rd] [Patch] Minor glitch in 'Writing R Extensions'

2012-09-03 Thread Dirk Eddelbuettel

The (marked up in info mode) manual Writing R Extensions says in 6.1.3

 -- Function: double fprec (double X, double DIGITS)
 Returns the value of X rounded to DIGITS decimal digits (after the
 decimal point).

 This is the function used by R's `round()'.
  ^^

 -- Function: double fround (double X, double DIGITS)
 Returns the value of X rounded to DIGITS _significant_ decimal
 digits.

 This is the function used by R's `signif()'.
  ^^^

I think that is crossed vis-a-vis the the corresponding R functions, ie

   'double fprec is used by 'signif (not round)

   'double fround' is used by 'round' (not signif)

as I just found out by trying to unit-test wrappers just added to Rcpp.

Sources seem to agree -- src/main/arithmetic.c has

case 10001: return Math2(args, fround);/* round(), src/nmath/fround.c */
case 10004: return Math2(args, fprec); /* signif(), src/nmath/fprec.c */

So with that I suggest to alter the R-exts.texi as the patch below does.

Hope this helps, Dirk


edd@max:/tmp$ diff -u R-exts.texi.orig R-exts.texi
--- R-exts.texi.orig2012-09-03 10:56:21.219528679 -0500
+++ R-exts.texi 2012-09-03 10:56:42.359529056 -0500
@@ -10659,14 +10659,14 @@
 Returns the value of @var{x} rounded to @var{digits} decimal digits
 (after the decimal point).
 
-This is the function used by @R{}'s @code{round()}.
+This is the function used by @R{}'s @code{signif()}.
 @end deftypefun
 
 @deftypefun double fround (double @var{x}, double @var{digits})
 Returns the value of @var{x} rounded to @var{digits} @emph{significant}
 decimal digits.
 
-This is the function used by @R{}'s @code{signif()}.
+This is the function used by @R{}'s @code{round()}.
 @end deftypefun
 
 @deftypefun double ftrunc (double @var{x})
edd@max:/tmp$ 



-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Duncan Murdoch

On 12-09-03 11:18 AM, Martin Maechler wrote:

Dirk Eddelbuettel 
 on Mon, 3 Sep 2012 09:34:06 -0500 writes:


 > On 3 September 2012 at 00:49, Henrik Bengtsson wrote:
 > | Hi, see thread "[Rd] Proposal: Mechanism for controlling the amount of
 > | testing 'R CMD check' performs" on April 8, 2012:
 > |
 > |   https://stat.ethz.ch/pipermail/r-devel/2012-April/063809.html

 > Good proposal, somehow I missed that at the time.
 > Something like this ought be to implemented in R proper.

I agree but the CRAN maintainers have to agree too.


 > In Rcpp, I am now using a similar
 > environment-variable-based approach, and it doesn't scale
 > particularly well if every (large) package does its own thing.

yes, my packages do their own thing too, now, e.g., Matrix
(not yet released):

doExtras <- interactive() || nzchar(Sys.getenv("R_MATRIX_CHECK_EXTRA")) ||
 identical("true", unname(Sys.getenv("R_PKG_CHECKING_doExtras")))

and then I use  if(doExtras) {  }
but I agree with Henrik that it would make sense to have more
than just two levels for the amount of testing, not just for CRAN.

An additional, slightly more interesting feature request that
you may also want in these cases, is the following:
Assume, that we have a function testingLevel()
and the following code should only be run, if the testing level
is 2 or higher

if(testingLevel() > 2) {
  ...1
  ...2
  
  
  ...n
}

Now what we all really wanted was that the  code
ran just as in toplevel.
While I think that's almost impossible,
as the .1 to .n must first be parsed all, and then
evaluated (which is already different from top level),
I would at least want that  the auto-printing worked like in
toplevel, so I don't have to write a  print(.) around every
..i that would autoprint if in toplevel, and of course does
*not* autoprint inside if(.) { .. }.



I prefer the current scheme where individual tests can be turned on and 
off.  The space of tests is a 2^N factorial space, not a chain of n 
possible levels.


The only problem I see with the current scheme is that code being tested 
can't find out which tests are being run.  In some cases, that's fine: 
there's no point in example code knowing about tests for consistency 
between documentation and implementation.  In other cases it might even 
be a good thing:  do you want packages to be able to hide dependencies 
on non-CRAN packages, for example?


Duncan Murdoch

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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Spencer Graves

Hi, Duncan et al.:


  I modified my CRAN() function (see below) to look for 
"_R_CHECK_TIMINGS_" and "R_CHECK_TIMINGS", but got "NOT CRAN" with "R 
CMD check --as-cran" from both.



  Suggestions?
  Thanks,
  Spencer
p.s.  This is fda available from R-Forge via "svn checkout 
svn://svn.r-forge.r-project.org/svnroot/fda/".  It currently is 
programmed to stop no matter what.  I want it to give an error "CRAN" 
with "R CMD check --as-cran" and "NOT CRAN" without "--as-cran".  
Currently, I get "NOT CRAN" for both.



On 9/3/2012 4:41 AM, Duncan Murdoch wrote:

On 12-09-03 1:43 AM, Spencer Graves wrote:

Hello, All:


The fda package has tests that run too long for CRAN's current
rules.  I'd like to wrap some examples in a construct like the 
following:



if(!CRAN()){
...
}


I tried the following:


CRAN <- function(x='_R_CHECK_CRAN_INCOMING_'){
  x. <- Sys.getenv(x)
  xl <- as.logical(x.)
  notCRAN <- is.na(xl) || xl
#
  return(!notCRAN)
}


The companion help page included the following example:


if(CRAN()){
stop('CRAN')
} else {
stop('NOT CRAN')
}


This reported "NOT CRAN" even with "R CMD check --as-cran".


There's no user-visible setting for --as-cran, because it just sets a 
number of other options.  You could query one of those. The settings 
that are visible are


_R_CHECK_TIMINGS_  (which seems most relevant to you)
_R_CHECK_INSTALL_DEPENDS_
_R_CHECK_NO_RECOMMENDED_
_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_

So I'd check the value in _R_CHECK_TIMINGS_, or maybe just its existence.

Duncan Murdoch



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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Duncan Murdoch

On 12-09-03 7:25 PM, Spencer Graves wrote:

Hi, Duncan et al.:


I modified my CRAN() function (see below) to look for
"_R_CHECK_TIMINGS_" and "R_CHECK_TIMINGS", but got "NOT CRAN" with "R
CMD check --as-cran" from both.


Suggestions?
Thanks,
Spencer
p.s.  This is fda available from R-Forge via "svn checkout
svn://svn.r-forge.r-project.org/svnroot/fda/".  It currently is
programmed to stop no matter what.  I want it to give an error "CRAN"
with "R CMD check --as-cran" and "NOT CRAN" without "--as-cran".
Currently, I get "NOT CRAN" for both.


The problem is with your test.  If I put print(names(Sys.getenv())) into 
an example, I see _R_CHECK_TIMINGS_ if and only if I do the check with 
--as-cran.  The value is supposed to be a number, not a logical.


Duncan Murdoch





On 9/3/2012 4:41 AM, Duncan Murdoch wrote:

On 12-09-03 1:43 AM, Spencer Graves wrote:

Hello, All:


 The fda package has tests that run too long for CRAN's current
rules.  I'd like to wrap some examples in a construct like the
following:


if(!CRAN()){
...
}


 I tried the following:


CRAN <- function(x='_R_CHECK_CRAN_INCOMING_'){
   x. <- Sys.getenv(x)
   xl <- as.logical(x.)
   notCRAN <- is.na(xl) || xl
#
   return(!notCRAN)
}


 The companion help page included the following example:


if(CRAN()){
 stop('CRAN')
} else {
 stop('NOT CRAN')
}


 This reported "NOT CRAN" even with "R CMD check --as-cran".


There's no user-visible setting for --as-cran, because it just sets a
number of other options.  You could query one of those. The settings
that are visible are

_R_CHECK_TIMINGS_  (which seems most relevant to you)
_R_CHECK_INSTALL_DEPENDS_
_R_CHECK_NO_RECOMMENDED_
_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_

So I'd check the value in _R_CHECK_TIMINGS_, or maybe just its existence.

Duncan Murdoch





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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Spencer Graves

Hi, Duncan:


  Duh... Thanks.  I should have been able to figure that out for 
myself.  Your help produced a solution much quicker.



  Thank again.
  Spencer


On 9/3/2012 4:52 PM, Duncan Murdoch wrote:

On 12-09-03 7:25 PM, Spencer Graves wrote:

Hi, Duncan et al.:


I modified my CRAN() function (see below) to look for
"_R_CHECK_TIMINGS_" and "R_CHECK_TIMINGS", but got "NOT CRAN" with "R
CMD check --as-cran" from both.


Suggestions?
Thanks,
Spencer
p.s.  This is fda available from R-Forge via "svn checkout
svn://svn.r-forge.r-project.org/svnroot/fda/".  It currently is
programmed to stop no matter what.  I want it to give an error "CRAN"
with "R CMD check --as-cran" and "NOT CRAN" without "--as-cran".
Currently, I get "NOT CRAN" for both.


The problem is with your test.  If I put print(names(Sys.getenv())) 
into an example, I see _R_CHECK_TIMINGS_ if and only if I do the check 
with --as-cran. The value is supposed to be a number, not a logical.


Duncan Murdoch





On 9/3/2012 4:41 AM, Duncan Murdoch wrote:

On 12-09-03 1:43 AM, Spencer Graves wrote:

Hello, All:


 The fda package has tests that run too long for CRAN's 
current

rules.  I'd like to wrap some examples in a construct like the
following:


if(!CRAN()){
...
}


 I tried the following:


CRAN <- function(x='_R_CHECK_CRAN_INCOMING_'){
   x. <- Sys.getenv(x)
   xl <- as.logical(x.)
   notCRAN <- is.na(xl) || xl
#
   return(!notCRAN)
}


 The companion help page included the following example:


if(CRAN()){
 stop('CRAN')
} else {
 stop('NOT CRAN')
}


 This reported "NOT CRAN" even with "R CMD check --as-cran".


There's no user-visible setting for --as-cran, because it just sets a
number of other options.  You could query one of those. The settings
that are visible are

_R_CHECK_TIMINGS_  (which seems most relevant to you)
_R_CHECK_INSTALL_DEPENDS_
_R_CHECK_NO_RECOMMENDED_
_R_SHLIB_BUILD_OBJECTS_SYMBOL_TABLES_

So I'd check the value in _R_CHECK_TIMINGS_, or maybe just its 
existence.


Duncan Murdoch








--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com

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


Re: [Rd] Environment when NextMethod is used

2012-09-03 Thread Hadley Wickham
Any ideas? Is this a big or a deliberate feature?
Hadley

On Saturday, September 1, 2012, Winston Chang wrote:

> I'm running into some hard-to-understand behavior with the evaluation
> environment when NextMethod is used. I'm using square-bracket indexing
> into objects, and the evaluation environment of the expression inside
> the square brackets seems to change depending on what kind of
> comparison operators are used.
>
> This behavior happens when the following conditions are met (this is
> what I've found; I'm sure that these aren't necessary and sufficient
> conditions):
> - I call a function from an attached package.
> - The function uses square bracket indexing with a class that has its
> own definition of the operator, such as `[.factor` or `[.POSIXct`. (If
> a vector of numerics is used, the error doesn't happen.)
> - The indexing function uses NextMethod("[").
> - An S3 method is used within the square brackets. (When a regular
> function is used, there's no error.)
> - The S3 method is from a package that is an import for the original
> function's package, but this package is not attached. (If the package
> is attached, then the error doesn't happen because R finds the method
> in the standard search path.)
> - An operator like == is used. (If the %in% operator is used, the
> error doesn't happen.)
>
>
> This may sound very abstract. I've created a sample package that
> illustrates the behavior. The package is called envtest, and it has a
> function called envtest(), which uses an S3 method from the nlme
> package. nlme is listed as an import.
>
> You can either clone the repository here:
>   https://github.com/wch/envtest
> Or you can install it with devtools, using:
>   library(devtools)
>   dev_mode()
>   install_github('envtest', 'wch')
>
>
>
> The envtest() function tries to index into a factor in different ways,
> and prints the output for each one. This is the content of the
> function. (If you load it from the global environment, it won't have
> the same error, since the issue has to do with an import):
>
> envtest <- function() {
>   dat <- data.frame(x = 0, y = 0)
>   f <- factor(c("a", "b"))
>
>   # Print the starting data
>   cat("\nf: ")
>   cat(f)
>
>   cat("\n\nTests with %in% operator ")
>
>   # OK
>   cat('\n"x" %in% Names(y ~ x, data = dat): ')
>   cat("x" %in% Names(y ~ x, data = dat))
>
>   # OK: Save boolean values to idx, then use f[idx]
>   cat('\nidx <- "x" %in% Names(y ~ x, data = dat); f[idx] : ')
>   cat({idx <- "x" %in% Names(y ~ x, data = dat); f[idx]})
>
>   # OK: Use the expression with S3 function Names directly inside of []
>   cat('\nf["x" %in% Names(y ~ x, data = dat)] : ')
>   cat(f["x" %in% Names(y ~ x, data = dat)])
>
>
>   cat("\n\nTests with == operator --")
>
>   # OK
>   cat('\n"x" == Names(y ~ x, data = dat)  : ')
>   cat("x" == Names(y ~ x, data = dat))
>
>   # OK: Save boolean values to idx, then use f[idx]
>   cat('\nidx <- "x" == Names(y ~ x, data = dat); f[idx]   : ')
>   cat({idx <- "x" == Names(y ~ x, data = dat); f[idx]})
>
>   # Error: Use the expression with S3 function Names directly inside of []
>   cat('\nf["x" == Names(y ~ x, data = dat)]   : ')
>   cat(f["x" == Names(y ~ x, data = dat)])
>
>   invisible()
> }
>
>
>
> This is what happens when I run the envtest() function. All the
> indexing operations work, except the last one, where, inside the
> square brackets, the == operator is used, and it calls the S3 method
> from an imported package.
>
> > library(envtest)
> > envtest()
> f: 1 2
>
> Tests with %in% operator 
> "x" %in% Names(y ~ x, data = dat): TRUE
> idx <- "x" %in% Names(y ~ x, data = dat); f[idx] : 1 2
> f["x" %in% Names(y ~ x, data = dat)] : 1 2
>
> Tests with == operator --
> "x" == Names(y ~ x, data = dat)  : FALSE TRUE
> idx <- "x" == Names(y ~ x, data = dat); f[idx]   : 2
> f["x" == Names(y ~ x, data = dat)]   : Error in Names(y ~
> x, data = dat) : could not find function "Names"
>
>
> When I set options(error=recover), it's possible to investigate the
> environment where it's trying to evaluate the expression Names(),
> when it runs into the error:
>
> Enter a frame number, or 0 to exit
>
> 1: envtest()
> 2: envtest.r#40: cat(f["x" == Names(y ~ x, data = dat)])
> 3: f["x" == Names(y ~ x, data = dat)]
> 4: `[.factor`(f, "x" == Names(y ~ x, data = dat))
> 5: NextMethod("[")
> 6: Names(y ~ x, data = dat)
>
> Selection: 5
>
> Browse[1]> environment()
> 
> Browse[1]> parent.env(environment())
> 
> Browse[1]> parent.env(parent.env(environment()))
> 
>
>
> When == is used, it tries to evaluate the expression Names() in
> the environment namespace:base, and it fails because it can't find the
> function.

Re: [Rd] if(--as-cran)?

2012-09-03 Thread Hadley Wickham
> | Hi, see thread "[Rd] Proposal: Mechanism for controlling the amount of
> | testing 'R CMD check' performs" on April 8, 2012:
> |
> |   https://stat.ethz.ch/pipermail/r-devel/2012-April/063809.html
>
> Good proposal, somehow I missed that at the time.  Something like this ought
> be to implemented in R proper.
>
> In Rcpp, I am now using a similar environment-variable-based approach, and it
> doesn't scale particularly well if every (large) package does its own thing.

Is there any approach that's going to be particularly better than
scaling out CRAN's build servers?  As a particularly profuse package
author, I'd be happy to pay for the computing time that it takes to
run a full set of tests on my package (and this seems feasible in the
era of on-demand cloud computing).

Hadley

-- 
Assistant Professor
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [Rd] if(--as-cran)?

2012-09-03 Thread Spencer Graves

On 9/3/2012 7:59 PM, Hadley Wickham wrote:

| Hi, see thread "[Rd] Proposal: Mechanism for controlling the amount of
| testing 'R CMD check' performs" on April 8, 2012:
|
|   https://stat.ethz.ch/pipermail/r-devel/2012-April/063809.html

Good proposal, somehow I missed that at the time.  Something like this ought
be to implemented in R proper.

In Rcpp, I am now using a similar environment-variable-based approach, and it
doesn't scale particularly well if every (large) package does its own thing.

Is there any approach that's going to be particularly better than
scaling out CRAN's build servers?  As a particularly profuse package
author, I'd be happy to pay for the computing time that it takes to
run a full set of tests on my package (and this seems feasible in the
era of on-demand cloud computing).

Hadley

  Jim Ramsay suggested we have CRAN generate a pro-forma invoice 
when a package is first submitted to CRAN and on each anniversary 
thereafter that would be like page charges for journals:  If you work 
for an organization that knows how to pay invoices, you submit the 
invoice to that system.  Ramsay said he has grant money and would be 
happy to pay a reasonable fee, but he needs an invoice.  If you aren't 
in such an organization, you are free to plead poverty and pay anything 
or nothing.  I think we should do the same for R-Forge.



  I think the fee should be set high enough that the money 
generated would be enough to pay for more hardware AND for someone to 
maintain the system.  The entirety of humanity will benefit if Ripley, 
Hornik, Ligges, Theussl, Zeileis and others spend more time developing 
better statistical algorithms and less struggling with computer hardware 
and operating systems just to keep CRAN and R-Forge functioning.  These 
folks and others have done a great job in bringing R to where it is 
today.  There are now over 4,000 packages on CRAN.  If 25% of those pay, 
say, 200 (Euros or dollars) per year, for example, that should be enough 
to hire a competent sys admin or two with an adequate hardware budget to 
keep it all running, I think.



  Thanks, Hadley.
  Spencer


--
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com

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