[R] Nulls being coerced : Bug or design?

Bert Gunter gunter.berton at gene.com
Fri Jun 21 22:53:25 CEST 2013


Well, feel free to make up any semantics that you like for a language
you write, but R already has its own and tells you what to expect:

>From ?NULL:

NULL can be indexed (see Extract) in just about any syntactically
legal way: whether is makes sense or not, the result is always NULL.
Objects with value NULL can be changed by replacement operators and
will be coerced to the type of the right-hand side.

Cheers,
Bert

On Fri, Jun 21, 2013 at 1:21 PM, Saptarshi Guha
<saptarshi.guha at gmail.com> wrote:
> Hello,
>
> Consider the following transcript
>
>> x=NULL
>> x$date=10
>> x
> $date
> [1] 10
>
> or
>
>> x=NULL
>> x[10]=10
>> x
>  [1] NA NA NA NA NA NA NA NA NA 10
>
>
> Wouldn't one expect that x remain NULL despite the further additions (i.e
> the x$date, x[10]) etc? Is coercing appropriate here?
>
> Cheers
> Saptarshi
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list