[Rd] Setting of "balanced" attribute by 'length<-.POSIXlt'

Suharto Anggono Suharto Anggono @uh@rto_@nggono @end|ng |rom y@hoo@com
Sat Dec 13 14:02:28 CET 2025


In R 4.5.2 (not before), `length<-.POSIXlt` sets "balanced" attribute of the result to TRUE only ifisTRUE(attr(x, "balanced")) && value <= length(x) .

For 'value' that is not a whole number, it is possible that value > length(x) and the length of the result is still length(x).
Instead ofvalue <= length(x) ,it is better to usevalue < length(x) + 1(not length(x) + 1L as length(x) may be .Machine$integer.max)orvalue - length(x) < 1Lortrunc(value) <= length(x)orlength(r) <= length(x)orlength(r$year) <= length(x)(or other component of 'r').
By the way, `length<-.POSIXlt` should also use unCfillPOSIXlt(x) instead of unclass(x). For example, when the maximum component length is 3 and a component has length 1 and 'value' (the assigned length) is 2.
If unCfillPOSIXlt(x) is used and is assigned to 'x', length of any component can be used.
	[[alternative HTML version deleted]]



More information about the R-devel mailing list