[R-pkg-devel] error in sample(), invalid 'size' argument

Roberts, David drobert@ @end|ng |rom mont@n@@edu
Wed Jan 15 19:25:55 CET 2020


Dear Bill, Dear Iñaki,

    Thank you both; I'm confident that you are right.  I realized a list 
or data.frame would generate that error message, but I did not know that 
NULL would also do so.

     This means the the error occurred in the previous function call 
which produced an output object that lacked the matrix expected at 
$member.  As Iñaki well notes, the existence of an object of the correct 
class doesn't guarantee it is well-formed.  On my machine (and those I 
have access to), str(mss) returns

  List of 7
  $ musubx  : num [1:78, 1:10] 1 1 1 1 1 1 1 1 1 1 ...
  $ member  : int [1:78, 1:10] 1 2 3 4 5 6 8 9 10 11 ...
  $ numset  : int 78
  $ size    : num 10
  $ alphac  : NULL
  $ distname: chr "dis.bc"
  $ numele  : int 150
  - attr(*, "class")= chr "mss"
  - attr(*, "call")= language maxsimset(dist = dis.bc, size = 10)
  - attr(*, "timestamp")= chr "Wed Jan 15 19:15:33 2020"

where clearly $member is a matrix with 10 columns.

    Unfortunately, I cannot generate the error on any machines I have 
access to and will have to find a debian machine running R-devel to do 
any debugging.

Thanks for your help, Dave

On 1/15/20 4:17 PM, William Dunlap wrote:
> If mss$member is not a matrix you will get that error because setsiz 
> will be NULL.
> 
>    > setsiz <- ncol( 33 )
>    > sample(1:3, setsiz)
>    Error in sample.int <http://sample.int>(length(x), size, replace, 
> prob) :
>      invalid 'size' argument
> 
> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com <http://tibco.com>
> 
> 
> On Wed, Jan 15, 2020 at 4:58 AM Roberts, David <droberts using montana.edu 
> <mailto:droberts using montana.edu>> wrote:
> 
>     Colleagues,
> 
>          I have a function (maxsimset) in package optpart that has
>     worked for
>     at least a decade, passes check --as-cran on my ubuntu-based system,
>     and
>     builds without errors at win-builder and CRAN windows, but fails at
>     CRAN
>     debian (unstable) with the error
> 
>       > mss.test(mss.10,shoshsite$elevation)
>     Error in sample.int <http://sample.int>(length(x), size, replace,
>     prob) :
>         invalid 'size' argument
>     Calls: mss.test -> sample -> sample.int <http://sample.int>
> 
>     an excerpt of the function is below
> 
>        1  mss.test <- function(mss,env,panel='all',
>        2              main=deparse(substitute(env)),...)
>        3  {
>        4      if (class(mss) != "mss") {
>        5          stop("You must pass an object of class mss ...")
>        6      }
>        7      if (!is.numeric(env)) {
>        8          stop("You must pass only numeric vectors ... ")
>        9      }
>     10      setsiz <- ncol(mss$member)
>     11      nset <- mss$numset
>     12      null <- rep(0,nset)
>     13      for (i in 1:nset) {
>     14          tmp <- sample(1:length(env),setsiz)
>     15          nullmin <- min(env[tmp])
>     16          nullmax <- max(env[tmp])
>     17          null[i] <- nullmax - nullmin
>     18      }
>     19         .     .      .
>     20         .     .      .
>     21         .     .      .
>     22  }
> 
>     The error occurs at line 14 in the excerpt above.  As you can see, the
>     'size' argument is setsiz, taken at line 10 as the ncol(mss$member);
>     mss
>     has already been checked for conformance and does indeed have a list
>     object matrix called $member.  In my tests, setsiz has mode numeric,
>     class integer, and size 1 as expected.  The specific error message I
>     receive can be generated from sample() if size is a list object or
>     data.frame, but not a vector or matrix.
> 
>     Since I cannot replicate the error on any machines I have access to, I
>     am at a loss for the reason behind the error.  If this should go to
>     R-devel with respect to r77656 ( 2020-01-12) please advise.
> 
>     Thanks in advance for any help, Dave
>     ______________________________________________
>     R-package-devel using r-project.org <mailto:R-package-devel using r-project.org>
>     mailing list
>     https://stat.ethz.ch/mailman/listinfo/r-package-devel
> 


More information about the R-package-devel mailing list