Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider returning NULL for empty dimnames for dfm and fcm #2274

Open
kbenoit opened this issue May 11, 2023 · 0 comments
Open

Consider returning NULL for empty dimnames for dfm and fcm #2274

kbenoit opened this issue May 11, 2023 · 0 comments

Comments

@kbenoit
Copy link
Collaborator

kbenoit commented May 11, 2023

Our current behaviour is always to return a character for docnames() and featnames(). This is built into how dimnames() works for fcm and dfm objects. But this is not the default behaviour for base::matrix objects, which return NULL for empty dimnames, and as of Matrix v1.5.5, the base behaviour will be enforced for all Matrix class objects. (see #2258)

library("quanteda")
#> Package version: 4.0.0
#> Unicode version: 14.0
#> ICU version: 71.1
#> Parallel computing: 10 of 10 threads used.
#> See https://quanteda.io for tutorials and examples.

dfmat <- quanteda:::make_null_dfm()
dimnames(dfmat)
#> $docs
#> character(0)
#> 
#> $features
#> character(0)
dimnames(as.matrix(dfmat))
#> $docs
#> NULL
#> 
#> $features
#> NULL

fcmat <- fcm(dfmat)
dimnames(fcmat)
#> $features
#> character(0)
#> 
#> $features
#> character(0)
dimnames(as.matrix(fcmat))
#> $features
#> NULL
#> 
#> $features
#> NULL

Created on 2023-05-11 with reprex v2.0.2

Our options are be one of:

  1. Keeping the current behaviour, which was fixed in Fix v3 matrix 1.5.5 #2267 and Fix v4 matrix 1.5.5 #2273, and always return character() for all -- including empty --empty docnames() and featnames(), and for dimnames() on these objects.
  2. Keeping the current behaviour for docnames() and featnames() as per (1), but changing dimnames() to return NULL when that function is called.
  3. Changing docnames(), featnames(), and dimnames() to return NULL when a dimension is empty. If we choose (3), then we would need to change the docnames() behaviour for all other objects for which docnames() methods are defined.

I would favour (2), and strongly consider (3), but this would need some tests.

@kbenoit kbenoit changed the title Consider making empty dimnames NULL for dfm and fcm Consider returning NULL for empty dimnames for dfm and fcm May 11, 2023
@kbenoit kbenoit modified the milestones: v4 release, v3.3.1 May 11, 2023
@kbenoit kbenoit removed this from the v4 release milestone Oct 18, 2023
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

No branches or pull requests

1 participant