bug in function bounds()
If the input is two discontinuous numbers, bounds returns a wrong value. If the input is one number, bounds report an error. For example,
bounds(c(2,5)) start end length [1,] 2 5 4
bounds(c(2)) Error in names(bounds) <- c("start", "end", "length") : 'names' attribute [3] must be the same length as the vector [2]
Comments (5)
-
reporter -
Right... In fact, duplicate the first number of 'nums', and you're there:
Include the following two lines after you check for length==1.
if (length(nums) == 2) nums <- c(nums[1], nums)
Not a very elegant solution either.. but it works.
-
-
assigned issue to
-
assigned issue to
-
reporter I think there is no need to check for length(nums) == 2. Because bounds() works well when length(nums) >= 2. We only need to check for length(nums) == 1. Thank you, Lars.
-
- changed status to resolved
I simply checked and it seems the bug has been removed
- Log in to comment
My suggestion is change following part
if (length(nums) <= 2) { bounds <- sort(nums) bounds <- c(bounds, (bounds[2] - bounds[1] + 1)) names(bounds) <- c("start", "end", "length") return(t(as.matrix(bounds))) }
to
if (length(nums) == 1) { bounds <- c(nums, nums, 1) names(bounds) <- c("start", "end", "length") return(t(as.matrix(bounds))) }