[Rd] R CMD check -- non S3 method warning

2012-04-21 Thread Whit Armstrong
I'm trying to R CMD check a package, and I'm getting the 'checking S3
generic/method consistency' warning.

I have written a function 'gamma.dist' which is _not_ an S3 method,
but happens to collide with the 'gamma' function from the R::base
namespace.

Is there a way of telling CMD check that the name is intentional and
is not meant to be an S3 method?

My function is defined as follows:

gamma.dist <- function(x,alpha,beta,observed=FALSE) {
attr(x,"distributed") <- "gamma"
attr(x,"alpha") <- substitute(alpha)
attr(x,"beta") <- substitute(beta)
attr(x,"observed") <- observed
attr(x,"env") <- new.env()
class(x) <- "mcmc.object"
x
}


with corresponding man page:
\name{normal.dist}
\alias{normal.dist}
\alias{uniform.dist}
\alias{gamma.dist}
\alias{bernoulli.dist}
\alias{binomial.dist}
...
...

\usage{
normal.dist(x, mu, tau, observed = FALSE)
uniform.dist(x, lower, upper, observed = FALSE)
gamma.dist(x, alpha, beta, observed = FALSE)
bernoulli.dist(x, p, observed = FALSE)
binomial.dist(x, n, p, observed = FALSE)
}

I am reluctant to change the name of the function b/c all my
distribution methods use the same convention of 'distribution
type'.dist.

Do CRAN maintainers view this warning as a blocker for the package
(full make check output below, which includes a few additional
warnings I'm in the process of fixing)?

Thanks,
Whit



* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building ‘rcppbugs_0.0.1.tar.gz’

* using log directory ‘/home/warmstrong/dvl/R.packages/rcppbugs.Rcheck’
* using R version 2.15.0 (2012-03-30)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘rcppbugs/DESCRIPTION’ ... OK
* this is package ‘rcppbugs’ version ‘0.0.1’
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking whether package ‘rcppbugs’ can be installed ... OK
* checking installed package size ... NOTE
  installed size is  8.4Mb
  sub-directories of 1Mb or more:
libs   8.1Mb
* 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 ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... WARNING
gamma:
  function(x)
gamma.dist:
  function(x, alpha, beta, observed)

See section ‘Generic functions and methods’ of the ‘Writing R
Extensions’ manual.
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... NOTE
S3 methods shown with full name in documentation object 'normal.dist':
  ‘gamma.dist’

The \usage entries for S3 methods should use the \method markup and
not their full name.
See the chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual.
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking line endings in C/C++/Fortran sources/headers ... OK
* checking line endings in Makefiles ... OK
* checking for portable compilation flags in Makevars ... WARNING
Non-portable flags in variable ‘PKG_CXXFLAGS’:
  -Wall -std=c++0x
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK
* checking compiled code ... OK
* checking examples ... OK
* checking PDF version of manual ... OK

WARNING: There were 2 warnings.
NOTE: There were 2 notes.
See
  ‘/home/warmstrong/dvl/R.packages/rcppbugs.Rcheck/00check.log’
for details.

warmstrong@krypton:~/dvl/R.packages$ R
> gamma
function (x)  .Primitive("gamma")

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


[Rd] csv version of data in an R object

2012-04-21 Thread Max Kuhn
For a package, I need to write a csv version of a data set to an R
object. Right now, I use:

out <- capture.output(
  write.table(x,
  sep = ",",
  na = "?",
  file = "",
  quote = FALSE,
  row.names = FALSE,
  col.names = FALSE))

To me, this is fairly slow; 131 seconds for a data frame with 8100
rows and 1400 columns.

The data will be in a data frame; I know write.table() would be faster
with a matrix. I was looking into converting the data frame to a
character matrix using as.matrix() or, better yet, format() prior to
the call above. However, I'm not sure what an appropriate value of
'digits' should be so that the character version of numeric data has
acceptable fidelity.

I also tried using a text connection and sink() as shown in
?textConnection but there was no speedup.

Any suggestions or ideas?

Thanks,

Max


> sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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_2.14.0

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


Re: [Rd] R CMD check -- non S3 method warning

2012-04-21 Thread Prof Brian Ripley

On 21/04/2012 14:18, Whit Armstrong wrote:

I'm trying to R CMD check a package, and I'm getting the 'checking S3
generic/method consistency' warning.

I have written a function 'gamma.dist' which is _not_ an S3 method,
but happens to collide with the 'gamma' function from the R::base
namespace.

Is there a way of telling CMD check that the name is intentional and
is not meant to be an S3 method?


More importantly, there is no way to tell the generic, and there is a 
"dist" class in use in the 'stats' package.




My function is defined as follows:

gamma.dist<- function(x,alpha,beta,observed=FALSE) {
 attr(x,"distributed")<- "gamma"
 attr(x,"alpha")<- substitute(alpha)
 attr(x,"beta")<- substitute(beta)
 attr(x,"observed")<- observed
 attr(x,"env")<- new.env()
 class(x)<- "mcmc.object"
 x
}


with corresponding man page:
\name{normal.dist}
\alias{normal.dist}
\alias{uniform.dist}
\alias{gamma.dist}
\alias{bernoulli.dist}
\alias{binomial.dist}
...
...

\usage{
normal.dist(x, mu, tau, observed = FALSE)
uniform.dist(x, lower, upper, observed = FALSE)
gamma.dist(x, alpha, beta, observed = FALSE)
bernoulli.dist(x, p, observed = FALSE)
binomial.dist(x, n, p, observed = FALSE)
}

I am reluctant to change the name of the function b/c all my
distribution methods use the same convention of 'distribution
type'.dist.

Do CRAN maintainers view this warning as a blocker for the package
(full make check output below, which includes a few additional
warnings I'm in the process of fixing)?


That's a question for them, not R-devel, isn't it?



Thanks,
Whit



* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building ‘rcppbugs_0.0.1.tar.gz’

* using log directory ‘/home/warmstrong/dvl/R.packages/rcppbugs.Rcheck’
* using R version 2.15.0 (2012-03-30)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘rcppbugs/DESCRIPTION’ ... OK
* this is package ‘rcppbugs’ version ‘0.0.1’
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking whether package ‘rcppbugs’ can be installed ... OK
* checking installed package size ... NOTE
   installed size is  8.4Mb
   sub-directories of 1Mb or more:
 libs   8.1Mb
* 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 ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking for unstated dependencies in R code ... OK
* checking S3 generic/method consistency ... WARNING
gamma:
   function(x)
gamma.dist:
   function(x, alpha, beta, observed)

See section ‘Generic functions and methods’ of the ‘Writing R
Extensions’ manual.
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... NOTE
S3 methods shown with full name in documentation object 'normal.dist':
   ‘gamma.dist’

The \usage entries for S3 methods should use the \method markup and
not their full name.
See the chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual.
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking line endings in C/C++/Fortran sources/headers ... OK
* checking line endings in Makefiles ... OK
* checking for portable compilation flags in Makevars ... WARNING
Non-portable flags in variable ‘PKG_CXXFLAGS’:
   -Wall -std=c++0x
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK
* checking compiled code ... OK
* checking examples ... OK
* checking PDF version of manual ... OK

WARNING: There were 2 warnings.
NOTE: There were 2 notes.
See
   ‘/home/warmstrong/dvl/R.packages/rcppbugs.Rcheck/00check.log’
for details.

warmstrong@krypton:~/dvl/R.packages$ R

gamma

function (x)  .Primitive("gamma")

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.

[Rd] Problem with args

2012-04-21 Thread Gabor Grothendieck
args ought to check that its argument is a function:

> max <- 3
> args(max)
NULL

e.g.

> args <- function(name) {
+ name <- match.fun(name)
+ base::args(name)
+ }
> args(max)
function (..., na.rm = FALSE)
NULL


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [Rd] Problem with args

2012-04-21 Thread Simon Urbanek

On Apr 21, 2012, at 1:03 PM, Gabor Grothendieck wrote:

> args ought to check that its argument is a function:
> 
>> max <- 3
>> args(max)
> NULL
> 
> e.g.
> 
>> args <- function(name) {
> + name <- match.fun(name)
> + base::args(name)
> + }
>> args(max)
> function (..., na.rm = FALSE)
> NULL
> 

You may want to read the docs in the first place:

Value:
[...]

 'NULL' in case of a non-function.

Cheers,
S

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


Re: [Rd] Problem with args

2012-04-21 Thread Gabor Grothendieck
On Sat, Apr 21, 2012 at 1:38 PM, Simon Urbanek
 wrote:
>
> On Apr 21, 2012, at 1:03 PM, Gabor Grothendieck wrote:
>
>> args ought to check that its argument is a function:
>>
>>> max <- 3
>>> args(max)
>> NULL
>>
>> e.g.
>>
>>> args <- function(name) {
>> +     name <- match.fun(name)
>> +     base::args(name)
>> + }
>>> args(max)
>> function (..., na.rm = FALSE)
>> NULL
>>
>
> You may want to read the docs in the first place:
>
> Value:
> [...]
>
>     'NULL' in case of a non-function.
>

My post wasn't about the return value -- it was about the fact that
the function name can be masked.  Try the example I posted.  I also
posted a solution.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [Rd] Problem with args

2012-04-21 Thread Gabor Grothendieck
On Sat, Apr 21, 2012 at 2:10 PM, Simon Urbanek
 wrote:
>
> On Apr 21, 2012, at 1:45 PM, Gabor Grothendieck wrote:
>
>> On Sat, Apr 21, 2012 at 1:38 PM, Simon Urbanek
>>  wrote:
>>>
>>> On Apr 21, 2012, at 1:03 PM, Gabor Grothendieck wrote:
>>>
 args ought to check that its argument is a function:

> max <- 3
> args(max)
 NULL

 e.g.

> args <- function(name) {
 +     name <- match.fun(name)
 +     base::args(name)
 + }
> args(max)
 function (..., na.rm = FALSE)
 NULL

>>>
>>> You may want to read the docs in the first place:
>>>
>>> Value:
>>> [...]
>>>
>>>     'NULL' in case of a non-function.
>>>
>>
>> My post wasn't about the return value -- it was about the fact that the 
>> function name can be masked.  Try the example I posted.  I also posted a 
>> solution.
>>
>
> You're passing a non-function (the value of 3) so, obviously you get NULL. I 
> think you're confusing function calls with values. What you probably intended 
> was
>

That's only a workaround but it does not address the problem that args
ought not to work that way.  args can gather all the information
needed to fetch the correct object but doesn't.  The second example
shows how it should work.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [Rd] Problem with args

2012-04-21 Thread Simon Urbanek

On Apr 21, 2012, at 1:45 PM, Gabor Grothendieck wrote:

> On Sat, Apr 21, 2012 at 1:38 PM, Simon Urbanek
>  wrote:
>> 
>> On Apr 21, 2012, at 1:03 PM, Gabor Grothendieck wrote:
>> 
>>> args ought to check that its argument is a function:
>>> 
 max <- 3
 args(max)
>>> NULL
>>> 
>>> e.g.
>>> 
 args <- function(name) {
>>> + name <- match.fun(name)
>>> + base::args(name)
>>> + }
 args(max)
>>> function (..., na.rm = FALSE)
>>> NULL
>>> 
>> 
>> You may want to read the docs in the first place:
>> 
>> Value:
>> [...]
>> 
>> 'NULL' in case of a non-function.
>> 
> 
> My post wasn't about the return value -- it was about the fact that the 
> function name can be masked.  Try the example I posted.  I also posted a 
> solution.
> 

You're passing a non-function (the value of 3) so, obviously you get NULL. I 
think you're confusing function calls with values. What you probably intended 
was

> args("max")
function (..., na.rm = FALSE) 
NULL

(again, see the documentation).

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


Re: [Rd] csv version of data in an R object

2012-04-21 Thread Barry Rowlingson
On Sat, Apr 21, 2012 at 3:28 PM, Max Kuhn  wrote:
> For a package, I need to write a csv version of a data set to an R
> object. Right now, I use:
>
>    out <- capture.output(
>                          write.table(x,
>                                      sep = ",",
>                                      na = "?",
>                                      file = "",
>                                      quote = FALSE,
>                                      row.names = FALSE,
>                                      col.names = FALSE))
>
> To me, this is fairly slow; 131 seconds for a data frame with 8100
> rows and 1400 columns.
>
> The data will be in a data frame; I know write.table() would be faster
> with a matrix. I was looking into converting the data frame to a
> character matrix using as.matrix() or, better yet, format() prior to
> the call above. However, I'm not sure what an appropriate value of
> 'digits' should be so that the character version of numeric data has
> acceptable fidelity.
>
> I also tried using a text connection and sink() as shown in
> ?textConnection but there was no speedup.
>

 You could try a loop over each row, and use 'paste' to join each
element in a row by commas. Then use 'paste' again to join everything
you've got (a vector of rows) by a '\n' character.

something like: paste(apply(x,1,paste,collapse=","),collapse="\n")   # untested

you probably also want to stick a final \n on it.

Is it faster? I don't know!

Barry

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


[Rd] Sending lists using .C

2012-04-21 Thread chris90nz
Hi,

I posted around a week ago and I will try this time with a more detailed
description.

I am converting R code to C code to boost speed as currently it takes a few
days to run. Now I will try describe this with as detail as possible.

I have a list of size 47. Each element of the list is itself a list of size
7, and each of these lists are arbitrarily long lists of integers.

I.e. If my main list is called Gcompat, then I could have Gcompat[[1]][[1]]
= 5, and Gcompat[[1]][[3]] = 1, 3, 6.

So Gcompat[[i]][[j]] = list of integers, where 1<=i<=47, 1<=j<=7. 

I have written the following code which will let me pass it through using .C
as two vectors, one containing the numbers contained in the lists all
concatenated, the other containing the indicies at which each list starts.

#
Gcompat_values = vector()
Gcompat_lengths = vector()
Gcompat_indicies = as.vector(0)
   
for(i in 1:S) {
  for (j in 1:L) {
Gcompat_values = c(Gcompat_values, Gcompat[[i]][[j]])
Gcompat_lengths = c(Gcompat_lengths, length(Gcompat[[i]][[j]]))
  }
}
   
for (i in 2:(length(Gcompat_lengths)+1)) {
  Gcompat_indicies[i] = Gcompat_indicies[i-1]+Gcompat_lengths[i-1]
}


This approach works, but is still slow (10,000 times doing this takes
~30seconds).

I know you can pass a list through by having the C function take as a
parameter SEXP*. However I am not familiar with using Rinternals.h and am a
little lost as to how I would access elements of my big list if I just pass
the whole thing through to a SEXP*.

The other thing is I have 2 lists to pass through like this, and another
with an arbitrary sized matrix instead of a list of integers, so I think the
only way I can do this efficiently is if I do pass these lists through to a
SEXP*.

Any thoughts would be greatly appreciated.

Cheers,

Chris 

--
View this message in context: 
http://r.789695.n4.nabble.com/Sending-lists-using-C-tp4577449p4577449.html
Sent from the R devel mailing list archive at Nabble.com.

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