From pdalgd at gmail.com  Sun Jun 20 23:11:36 2010
From: pdalgd at gmail.com (Peter Dalgaard)
Date: Mon, 21 Jun 2010 00:11:36 +0300
Subject: [Rd] proposed change to 'sample'
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D700031C9A21@NA-PA-VBE03.na.tibco.com>
References: <4C1DE879.6040303@pburns.seanet.com>
	<77EB52C6DD32BA4D87471DCD70C8D700031C9A21@NA-PA-VBE03.na.tibco.com>
Message-ID: <4C1E8408.1010609@gmail.com>

William Dunlap wrote:
>> -----Original Message-----
>> From: r-devel-bounces at r-project.org 
>> [mailto:r-devel-bounces at r-project.org] On Behalf Of Patrick Burns
....
>>
>> I propose adding an argument that allows
>> the user (programmer) to avoid that
>> ambiguity:
>>
>> function (x, size, replace = FALSE, prob = NULL,
>>      max = length(x) == 1L && is.numeric(x) && x >= 1)
> 
> S+'s sample() has an argument 'n' to achieve
> the same result.  It has been there since at
> least 2005 (S+ 7.0.6).  sample(n=n) means to
> return a sample from seq_along(n), where n must
> be a scalar nonnegative integer.  sample(x=x)
> retains it old ambiguous meaning.
>   sample(x, size = n, replace = F, prob = NULL, n = NULL, ...)

Hmm, that doesn't really solve the issue does it? I.e., you still cannot
conveniently sample from a vector that is possibly of size 1.

I would be more inclined to make sampling from a vector the normal case,
and default x to say 1:max(n, size), forcing users to say sample(n=5) if
sampling from x=1:5 is desired. This could be a manageable change; the
deprecation sequence is a bit painful to think through, though.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] proposed change to 'sample'
Peter Dalgaard