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"
changed for as.vector to unclass for 2.15.0
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