-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Hello,
I have something strange. I have a list of four sprays:
> groups
[[1]]
val
0 2 = 1
2 2 = 1
1 2 = -2
[[2]]
val
2 1 = -2
1 1 = 2
[[3]]
val
2 0 = 1
[[4]]
val
1 2 = -2
0 2 = -2I want to have them as character. Since there's not as.character.spray function - and I think it would be nice to have one -, I did my own function:
asCharacter <- function(poly) {
op <- options(polyform = TRUE, sprayvars = letters)
x <- capture.output(print(poly))
options(op)
x
}I apply my function to the list:
> lapply(groups, asCharacter)
[[1]]
[1] "+b^2 +a^2*b^2 -2*a*b^2" "+b^2 +a^2*b^2 -2*a*b^2"
[[2]]
[1] "-2*a^2*b +2*a*b" "-2*a^2*b +2*a*b"
[[3]]
[1] "+a^2" "+a^2"
[[4]]
[1] "-2*a*b^2 -2*b^2" "-2*a*b^2 -2*b^2"Every spray is duplicated! Do you have an idea way?
Another strange thing:
> str(groups)
List of 4
$ :Class 'spray' hidden list of 2
..$ index: int [1:3, 1:2] 0 2 1 2 2 2
..$ value: num [1:3] 1 1 -2
$ :List of 2
..$ index: int [1:2, 1:2] 2 1 1 1
..$ value: num [1:2] -2 2
..- attr(*, "class")= chr "spray"
$ :Class 'spray' hidden list of 2
..$ index: int [1, 1:2] 2 0
..$ value: num 1
$ :List of 2
..$ index: int [1:2, 1:2] 1 0 2 2
..$ value: num [1:2] -2 -2
..- attr(*, "class")= chr "spray"Sometimes this print "Class spray hidden list of 2", but not always.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels