-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add tokens_xptr object #2210
Add tokens_xptr object #2210
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Merge branch 'dev-xtokens' of https://github.com/quanteda/quanteda into dev-xtokens # Conflicts: # R/tokens-methods.R
This comment was marked as resolved.
This comment was marked as resolved.
Merge branch 'dev-xtokens' of https://github.com/quanteda/quanteda into dev-xtokens # Conflicts: # R/tokens_restore.R
I like the addition of the So the constructor and object class could just be called What do you think? |
|
For #2208, I created a tokens_xptr object, a sub-class of tokens, whose underlying object is an external pointer instead of a list. All the underlying C++ code for
tokens_*
functions are also upgraded to accept the new object.Users can switch between tokens and tokens_xptr objects via
as.tokens()
andas.tokens_xptr()
whenever they want to. If they applytokens_*
functions to old objects,as.tokens_xptr()
is applied to the input andas.tokens()
to the output internally, so they do not even notice the changes in underlying functions.Apart from the detail of the implementation, remaining design issues are when the
tokens_xptr
methods should return a deep copy of the input objects. Currently, a deep copy is returned after subsetting (e.g.[]
,tokens_subset()
andtokens_sample()
).We can create
tokens_xptr.corpus()
, ortokens.corpus(xptr = TRUE)
, to get tokens_xptr objects straight away.tokens.tokens()
is already a wrapper aroundtokens.tokens_xptr()
.We should also add
env
to functions that perform NSE just like I did intokens_group()
andtokens_sample()
. Otherwise, developers find it difficult to nest them in their functions.For now, I kept the old code for
dfm.tokens()
andtokens_recompile.tokens()
to compare results.