Hello everyone, my name is Robin and I work on computational statistics, mostly in R
frab's Introduction
frab's People
frab's Issues
replacement method bug
library("frab")
#>
#> Attaching package: 'frab'
#> The following object is masked from 'package:graphics':
#>
#> symbols
(x <- rfrab())
#> A frab object with hash a391ff3181befefb96022c7098781d567820b3c0 and entries
#> d e g h
#> 8 7 3 4
x[] <- 3
#> Error in .local(x, i, j, ..., value): replacement operation not defined in this case
Created on 2023-07-11 with reprex v2.0.2
it would seem that x[] <- 3
has a clear expectation.
bug in extraction
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
x <- frab(c(x=4,y=6,z=8))
x[is.na(x)]
#> The empty frab object
x[!is.na(x)]
#> The empty frab object
last line above is clearly a bug, the result should be x
.
bug in addition
suppressWarnings(library("frab"))
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
x <- frab(c(a=1,b=-4,c=2,d=5,e=6,f=-9))
x[x>5] + 1000
#> Error in as.frab(e2): argument not recognised; did you mean to pass a _named_ numeric vector?
Above I would expect the sum to be defined but it gives an inappropriate error
Function `frab()` really should be able to take a named _logical_ vector
and it can't:
library("frab")
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
frab(c(a=TRUE,b=TRUE,c=FALSE,d=TRUE))
#> Error in frab(c(a = TRUE, b = TRUE, c = FALSE, d = TRUE)): is.namedvector(x) is not TRUE
Created on 2023-07-26 with reprex v2.0.2
pmin is not used
In src/sparsetable_ops.cpp
, function List sparsetable_pmin()
is not used: in R
, pmin
is defined in terms of pmax()
,
specifically we have
pmin_pair_sparsetable
<- function(F1,F2){-pmax_pair_sparsetable(-F1,-F2)}`
bug in `sparsetable()`
suppressMessages(library("frab"))
(x <- sparsetable(matrix(letters[1:24],ncol=3),1))
#> val
#> a i q = 1
#> b j r = 0
#> c k s = 0
#> d l t = 0
#> e m u = 0
#> f n v = 0
#> h p x = 3
dput(x)
#> new("sparsetable", index = structure(c("a", "b", "c", "d", "e",
#> "f", "h", "i", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t",
#> "u", "v", "x"), dim = c(7L, 3L)), values = c(1, 4.65015486152201e-314,
#> 4.65625948802518e-310, 4.65626113840799e-310, 4.65626113840245e-310,
#> 4.94065645841247e-324, 3))
Created on 2023-08-09 with reprex v2.0.2
Above the values show crazy small values because the proper vector was not sent to sparsetable()
inefficiency in equality check
Look at the check for equality in frab.cpp
:
bool equal2_samesize(frab F1, frab F2){
for (auto it=F1.begin(); it != F1.end(); ++it){
const string symbol = it->first;
if(F1[symbol] != F2[symbol]){ // meat 1
return false;
} else {
F2.erase(symbol);
}
}
return F2.empty();
}
This is inefficient, given that F1
and F2
are the same size. If they are the same size, we can just iterate through F1
and return false
if it finds a difference and true
if the loop completes, with no need for an erase operation. I think the erase step was originally there to guard against incorrectly returning true
if F1
was a strict subset of F2
(and every entry of F1
agreed with the corresponding entry of F2
).
replacement with NA bug
library("frab")
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
set.seed(0)
x <- rfrab()
x
#> A frab object with entries
#> a b c d g i
#> 3 6 1 5 7 5
x["c"] <- 100
x
#> A frab object with entries
#> a b c d g i
#> 3 6 100 5 7 5
x["c"] <- NA
#> Error in .local(x, i, j, ..., value): replacement operation not defined in this case
Above x["c"] <- NA
has a well-defined meaning and I would expect it to work.
bug in `pmax()`
library("frab")
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
pmax(rfrab(),rfrab(),rfrab())
#> A frab object with entries
#> a b c d e f g h i
#> 13 4 4 1 4 3 8 3 7
pmax(rfrab(),rfrab(),rfrab(),rfrab())
#> Error in pmax_pair(...): unused argument (new("frab", x = c(7, 4, 1, 4, 4, 1, 6)))
Created on 2023-07-26 with reprex v2.0.2
colnames of index matrix get lost
suppressMessages(library("frab"))
I <- matrix(sample(letters[1:4],15,replace=T),ncol=3)
colnames(I) <- state.abb[1:3]
I
#> AL AK AZ
#> [1,] "b" "b" "c"
#> [2,] "d" "a" "b"
#> [3,] "c" "b" "a"
#> [4,] "c" "a" "d"
#> [5,] "b" "a" "b"
sparsetable(I)
#> val
#> b a b = 1
#> b b c = 1
#> c a d = 1
#> c b a = 1
#> d a b = 1
Created on 2023-08-11 with reprex v2.0.2
sparsetable comparison methods not well documented
Just looking at issue #25 it is not clear why a ==3
returns a disord
object and not some kind of Boolean sparsetable.
At least, the Rd
files don't make this clear.
from CRAN
Thanks,
Please do not start the description with "This package", package name,
title or similar.
Please add \value to .Rd files regarding exported methods and explain
the functions results in the documentation. Please write about the
structure of the output (class) and also what the output means. (If a
function does not return a value, please document that too, e.g.
\value{No return value, called for side effects} or similar)
Missing Rd-tags:
print.Rd: \value
rfrab.Rd: \value
zero.Rd: \value
Please fix and resubmit.
Best,
Benjamin Altmann
missing replacement methods
It seems to be quite difficult to replace values of a frab object. Given a frab with some negative values, it is quite easy to replace
the negative values with a particular scalar:
library("frab")
set.seed(0)
(x <- rfrab(10,-2:2))
#> A frab object with entries
#> c d e g i
#> -2 -1 2 1 2
x[x<0] <- 0
x
#> A frab object with entries
#> e g i
#> 2 1 2
However, something like abs(x)
seems to be much harder:
library("frab")
set.seed(0)
(x <- rfrab(10,-2:2))
#> A frab object with entries
#> c d e g i
#> -2 -1 2 1 2
abs(x)
#> Error in abs(x): non-numeric argument to mathematical function
x[x<0]
#> A frab object with entries
#> c d
#> -2 -1
x[x<0] <- -x[x<0]
#> Error in .local(x, i, j, ..., value): replacement operation not defined in this case
Above, x[x<0] <- -x[x<0]
would seem to have a very reasonable expectation, but it does not work, due to a lack of
setReplaceMethod("[",signature(x="frab",i="disord",j="missing",value="frab"),...)
which would seem to be relatively straightforward to implement. Actually the best way I have found in existing package idiom to achieve abs(x)
is this:
suppressMessages(library("frab"))
set.seed(0)
(x <- rfrab(10,-2:2))
#> A frab object with entries
#> c d e g i
#> -2 -1 2 1 2
frab(abs(as.namedvector(x)))
#> A frab object with entries
#> c d e g i
#> 2 1 2 1 2
Part of the problem is that we do not have a values<-()
method. But I need to make values()
and values<-()
in the disordR
package generic first.
not operator for `is.na()`
The "not" operator does not work for is.na()
:
suppressMessages(library("frab"))
(x <- frab(c(x=5,y=1,z=2)))
#> A frab object with entries
#> x y z
#> 5 1 2
x["y"] <- NA
is.na(x)
#> A disind object with hash eec061606d73bf83eced3b5d7d31b5b14459f96f and 1 (implementation-specific) elements
!is.na(x)
#> Error in !is.na(x): invalid argument type
Now I don't think that "!is.na(x)
" should work, but it is not documented clearly.
rfrabbb() infelicity
rfrabbb(n=10,i=5)
takes a very long time to run. This is because of the expand.grid()
constuction. Something like
replicate(5,paste(sample(letters,5,replace=TRUE),collapse=""))
# [1] "jydlp" "kumyb" "xwxmn" "tqvsd" "twiwk"
might be better.
sparsetable inequality (!=) not implemented
library("frab")
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
(x <- rspar2())
#> bar
#> foo A B C D E F
#> a 4 14 0 0 0 7
#> b 0 5 13 0 0 9
#> c 6 1 0 0 0 3
#> d 0 0 0 2 0 10
#> e 0 8 12 0 0 0
#> f 0 15 0 0 11 0
x == 3
#> A disord object with hash 5a45a89691589101cbf771e946c210366eeda5fd and elements
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE
#> (in some order)
x != 3
#> Error in x != 3: Comparison operator "!=" not implemented in this case
frab == named vector
suppressWarnings(library("frab"))
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
frab(c(a=1,b=2,c=3)) == c(a=1,b=2,c=3)
#>
#> disordR discipline error in:
#> values(e1) == e2
#> Error in check_matching_hash(e1, e2, match.call()):
#> cannot combine disord object with hash code 471a46a1167406f770fe039498ad8c1da1f59f6d with a vector
Above, the ==
operator has a clear expectation (TRUE
) and it would be reasonable (?) to coerce the RHS to a frab
before attempting the coercion
replacement methods for `names`
Wouldn't it be nice to explicitly reset the names
of a frab
object:
library("frab")
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
(a <- frab(c(my_flob = 3, my_banana=1, my_float = 22)))
#> A frab object with entries
#> my_banana my_float my_flob
#> 1 22 3
gsub("my_","",names(a))
#> A disord object with hash c74a27de91c41202410d366d87f5777a00c3d172 and elements
#> [1] "banana" "float" "flob"
#> (in some order)
names(a) <- gsub("my_","",names(a))
#> Error in names(a) <- gsub("my_", "", names(a)): invalid to use names()<- on an S4 object of class 'frab'
(a_desired <- frab(c(flob = 3, banana=1, float = 22)))
#> A frab object with entries
#> banana float flob
#> 1 22 3
Above we see that names<-()
is not implemented. It would be nice to have replacement methods defined so that
names(a) <- gsub("my_","",names(a))
gives a_desired
.
In passing, I would say I am delighted and surprised that gsub()
takes, and returns, a disord
object. This should be documented somewhere.
x[is.na(x)] fails if empty
suppressMessages(library("frab"))
(x <- frab(c(x=5,y=1,z=2)))
#> A frab object with entries
#> x y z
#> 5 1 2
x["y"] <- NA
x[is.na(x)]
#> A frab object with entries
#> y
#> NA
x[is.na(x)] <- 33
x[is.na(x)]
#> Error in .local(x, i, j = j, ..., drop): not implemented
Above, the first call to x[is.na(x)]
works fine, extracting element y
. But the second fails.
pmin() and pmax()
library("frab")
library("disordR")
#> Loading required package: Matrix
#>
#> Attaching package: 'disordR'
#> The following object is masked from 'package:frab':
#>
#> values
(x <- frab(c(a=1,b=2,c=3)))
#> A frab object with entries
#> a b c
#> 1 2 3
(y <- frab(c(b=4,c=1,d=144)))
#> A frab object with entries
#> b c d
#> 4 1 144
pmin(x,y)
#> Warning in is.na(mmm): is.na() applied to non-(list or vector) of type 'S4'
#> Warning in is.na(each): is.na() applied to non-(list or vector) of type 'S4'
#> Error in mmm > each: comparison '">"' not for frabs
Above, I would expect pmin(x,y)
to give frab(c(a=1,b=2,c=1))
[NB d
has disappeared]
bug in replacement
library("frab")
library("disordR")
#> Loading required package: Matrix
#>
#> Attaching package: 'disordR'
#> The following object is masked from 'package:frab':
#>
#> values
x <- frab(c(a=1,b=2,c=3,i=4))
x
#> A frab object with entries
#> a b c i
#> 1 2 3 4
x[] <- c(4,6,77,6)
x
#> A frab object with entries
#> a b c i
#> 4 6 77 6
above I would expect x[] <- c(4,6,77,6)
to return a disord discipline error
powers and symbols terminology is outdated
I've realised that the main purpose of the frab
package is as an alternative interpretation of named vectors.
Although powers
and symbols
are suitable if one considers the Free Abelian Group as a special case of the Free Group [as implemented by freegroup
], they are somewhat confusing and weird if one is looking for a method to manipulate named vectors.
we should have values
and names
instead.
summary() method unhelpful
library("frab")
#>
#> Attaching package: 'frab'
#> The following objects are masked from 'package:base':
#>
#> pmax, pmin
x <- rfrab()
x
#> A frab object with entries
#> b c d e f g h i
#> 6 2 3 3 4 5 3 5
summary(x)
#> Length Class Mode
#> 8 frab S4
Created on 2023-08-02 with reprex v2.0.2
infelicity in comparison methods
library("frab")
#>
#> Attaching package: 'frab'
#> The following object is masked from 'package:graphics':
#>
#> symbols
(x <- frab(c(x=5,a=3,d=6)))
#> A frab object with hash 25076b3f8c2dbd97d18146872eb27d08034b8dab and entries
#> a d x
#> 3 6 5
x == 3
#> A disord object with hash 25076b3f8c2dbd97d18146872eb27d08034b8dab and elements
#> [1] "a"
#> (in some order)
Created on 2023-07-11 with reprex v2.0.2
disordR discipline violation
suppressPackageStartupMessages(library("frab"))
x <- frab(c(a=-3,b=-1,c=-2,d=1,f=-1,h=1,i=-1))
x
#> A frab object with entries
#> a b c d f h i
#> -3 -1 -2 1 -1 1 -1
x[x>0]
#> A frab object with entries
#> d h
#> 1 1
x[x>0] + 1:2
#> A frab object with entries
#> d h
#> 2 3
Above we see a bug, surely x[x>0] + 1:2
should raise a disordR error?
bug in replacement methods
library("frab")
x <- frab(c(a=1,b=2,c=3,i=4))
x
#> A frab object with entries
#> a b c i
#> 1 2 3 4
x[x>2] <- 33
x
#> A frab object with entries
#> 1 2 a b c i
#> 33 33 1 2 33 33
Created on 2023-07-13 with reprex v2.0.2
null sparstable object fail
suppressMessages(library("frab"))
a <- rspar()
a-a
#> Error in eval(expr, envir, enclos): Not compatible with STRSXP: [type=NULL].
Created on 2023-08-12 with reprex v2.0.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.