Bug 14839 - units<- drops names
units<- drops names
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Language
R 2.13.1
x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-11 02:10 UTC by Seth Roberts
Modified: 2012-03-12 22:07 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Seth Roberts 2012-03-11 02:10:57 UTC
Using the units function with a difftime object changes other attributes. Here is an example:

> t1=Sys.time()
> t2=Sys.time()
> t3=difftime(t1,t2)
> t3
Time difference of -7.624 secs
> names(t3)="test"
> names(t3)
[1] "test"
> units(t3)="mins"
> names(t3)
[1] "secs"
Comment 1 Brian Ripley 2012-03-12 22:07:21 UTC
changed for as.vector to unclass for 2.15.0
Comment 2 Brian Ripley 2012-03-13 01:53:07 UTC
On 11/03/2012 01:10, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14839
>
>             Summary: units function does not work properly
>             Product: R
>             Version: R 2.13.1
>            Platform: x86_64/x64/amd64 (64-bit)
>          OS/Version: Windows 64-bit
>              Status: NEW
>            Severity: normal
>            Priority: P5
>           Component: Language
>          AssignedTo: R-core@R-project.org
>          ReportedBy: twoutopias@gmail.com
>     Estimated Hours: 0.0
>
>
> Using the units function with a difftime object changes other attributes. Here
> is an example:


First, note that you are actually using the units<- function here, not 
units.

Second, all I see about this is

      The units of a ‘"difftime"’ object can be extracted by the ‘units’
      function, which also has an replacement form.  If the units are
      changed, the numerical value is scaled accordingly.

and no claim that anything is preserved.  And the presence of 
as.vector() in the code indicates that the author did not intend to 
preserve attributes.  Picking up "secs" was almost certainly a mistake 
though.

But to say it 'does not work properly' you need to demonstrate that it 
is documented to preserve other attributes.  I don't see the evidence here.

Finally, 2.13.1 is several versions old: you are asked only to report on 
current R (2.15.0 alpha now, since both the 2.13.x and 2.14.x series are 
closed).


>> t1=Sys.time()
>> t2=Sys.time()
>> t3=difftime(t1,t2)
>> t3
> Time difference of -7.624 secs
>> names(t3)="test"
>> names(t3)
> [1] "test"
>> units(t3)="mins"
>> names(t3)
> [1] "secs"
>



-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595