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

Can't easily rename docvars #1603

Closed
kbenoit opened this issue Feb 12, 2019 · 1 comment
Closed

Can't easily rename docvars #1603

kbenoit opened this issue Feb 12, 2019 · 1 comment

Comments

@kbenoit
Copy link
Collaborator

kbenoit commented Feb 12, 2019

The indexing is clearly off:

library("quanteda", warn.conflicts = FALSE)
## Package version: 1.4.0
## Parallel computing: 2 of 12 threads used.
## See https://quanteda.io for tutorials and examples.

corp <- corpus(c("A b c d.", "A a b. B c."),
  docvars = data.frame(testdv = 10:11)
)
summary(corp)
## Corpus consisting of 2 documents:
## 
##   Text Types Tokens Sentences testdv
##  text1     5      5         1     10
##  text2     6      7         2     11
## 
## Source: /private/var/folders/1v/ps2x_tvd0yg0lypdlshg_vwc0000gp/T/RtmpwTZK9J/reprexae23aa52f45/* on x86_64 by kbenoit
## Created: Tue Feb 12 12:19:06 2019
## Notes:

names(docvars(corp))[1] <- "renameddv"
docvars(corp)
##       testdv renameddv
## text1     10        10
## text2     11        11
summary(corp)
## Corpus consisting of 2 documents:
## 
##   Text Types Tokens Sentences testdv renameddv
##  text1     5      5         1     10        10
##  text2     6      7         2     11        11
## 
## Source: /private/var/folders/1v/ps2x_tvd0yg0lypdlshg_vwc0000gp/T/RtmpwTZK9J/reprexae23aa52f45/* on x86_64 by kbenoit
## Created: Tue Feb 12 12:19:06 2019
## Notes:
@kbenoit
Copy link
Collaborator Author

kbenoit commented Feb 13, 2019

I experimented with this for a bit and it's a deep problem, due to the deep and mysterious nature of names<-. I am not sure there is actually a way for us to do this on the data.frame itself without also reassigning it to the corpus.

kbenoit added a commit that referenced this issue Feb 13, 2019
- fixes names(docvars())<- to solve #1603
- linting changes for docvars.R
- ensures V1, V2, ... names for docvars without names (vectors)
@kbenoit kbenoit closed this as completed Feb 13, 2019
kbenoit added a commit to quanteda/blog.quanteda.org that referenced this issue Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants