Skip to content

Conversation

@rehbergT
Copy link

@rehbergT rehbergT commented May 5, 2023

Hello,
I have observed that selecting individual elements, rows, or columns of a matrix with row names produces an error. A similar error occurs when selecting a vector or its sub-elements.

library(float)

x <- matrix(1:9, 3)
rownames(x) <- as.character(paste("row ", seq(3)))
colnames(x) <- as.character(paste("col ", seq(3)))

y <- as.float(x)

print(y[1, 1])      # -> Error in `rownames<-`(`*tmp*`, value = "row  1") : attempt to set 'rownames' on an object with no dimensions
print(y[1:2, 1])    # -> Error in `rownames<-`(`*tmp*`, value = "row  1") : attempt to set 'rownames' on an object with no dimensions
print(y[1, 1:2])    # -> Error in `rownames<-`(`*tmp*`, value = "row  1") : attempt to set 'rownames' on an object with no dimensions
print(y[1:2, 1:2])  # -> Error in `rownames<-`(`*tmp*`, value = "row  1") : attempt to set 'rownames' on an object with no dimensions


x <- 1:9
names(x) <- as.character(paste("ele ", seq(9)))

y <- as.float(x)
print(y)     # -> Error in names(d) = names(x)[j] :  'names' attribute [9] must be the same length as the vector [5]
print(y[1])  # -> Error in names(d) = names(x)[j] :  'names' attribute [9] must be the same length as the vector [5]

This pull request addresses these issues for me. However, I am unable to determine if it may have any unintended consequences.

Morover, I noticed that printing a vector still looks odd and should be checked.

x <- 1:9
names(x) <- as.character(paste("ele ", seq(9)))
y <- as.float(x)
print(y)
> # A float32 vector: 9
> ele  1 ele  2 ele  3 ele  4 ele  5       1      2      3      4      5  ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant