You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow locking or protecting a data.table from any modifications #1086
I would like to be able to make a data.table unmodifiable. In the comments below my question, two changes to the data.table package are proposed by other users:
make modify-by-reference functions respect the lockBinding() function
I think OP wants to prevent semi-accidental modifies, not intentional ones. To achieve what the above drop example does, I'd just use copy now and imo that's easier/more understandable.
Good point.
I'm working on package which injects read.only branch functionality into data.table, so user can stick to data.table and prevent not intentional modification. Still it can be improved for [, := ] detection as it now copies the object even if you are not using :=. But one extra copy is a cheap trade-off for locking DT.
@ClaytonJY I just pushed that functionality into separate package. It allows you to stick to data.table master. jangorecki/dtq will inject same functionality as mentioned data.table branch.
It is heavy in dev but read.only feature is stable. If you want to use just read.only feature you might want to turn off the main feature of package by options("dtq.log" = FALSE).
Update: The package dtq by @jangorecki implements this feature by implicitly copying the data.table, but I would like to avoid making a copy and prefer getting an explicit error so that the developer can recognize the problem (violation of read only data).
Is it possible to add this feature into the data.table package?
THX!
PS: Code snippet in the dtq package (injected into the data.table):
# read.only mode
if(isTRUE(attr(x,"read.only",TRUE))){
x <- copy(x)
setattr(x,"read.only",NULL)
}
changed the title [-][Request] Allow locking or protecting a data.table from any modifications[/-][+]Allow locking or protecting a data.table from any modifications[/+]on Apr 3, 2020
As noted in #778, I'm not sure it's possible to use the lockBinding() mechanism directly -- it's simply too hard to tell in general when an object is locked using the public APIs R provides (please CMIIW).
However, we could still fulfill this issue with a new function like lockTable() that has a familiar name to lockBinding() but actually works by setting an attribute that assign() can read & respond to.
This would also get around the back-compatibility flaws of the lockBinding() approach mentioned in #778.
Activity
jangorecki commentedon Mar 19, 2015
maybe we can use
dropparam?This way we can not modify our initial data.table, and have the results materialized as copy. And there is
dropfinally useful.eantonya commentedon Mar 23, 2015
I think OP wants to prevent semi-accidental modifies, not intentional ones. To achieve what the above
dropexample does, I'd just usecopynow and imo that's easier/more understandable.jangorecki commentedon Mar 23, 2015
Good point.
I'm working on package which injects
read.onlybranch functionality into data.table, so user can stick to data.table and prevent not intentional modification. Still it can be improved for[, := ]detection as it now copies the object even if you are not using:=. But one extra copy is a cheap trade-off for locking DT.jangorecki commentedon Mar 25, 2015
@ClaytonJY I just pushed that functionality into separate package. It allows you to stick to data.table master. jangorecki/dtq will inject same functionality as mentioned data.table branch.
It is heavy in dev but
read.onlyfeature is stable. If you want to use justread.onlyfeature you might want to turn off the main feature of package byoptions("dtq.log" = FALSE).aryoda commentedon Jul 9, 2017
Any news about the state of locking data.tables? I ran into the same requirement, see
https://stackoverflow.com/questions/44995065/r-how-to-make-a-data-table-read-only-without-copying-it-e-g-for-data-validat
Update: The package
dtqby @jangorecki implements this feature by implicitly copying the data.table, but I would like to avoid making a copy and prefer getting an explicit error so that the developer can recognize the problem (violation of read only data).Is it possible to add this feature into the
data.tablepackage?THX!
PS: Code snippet in the
dtqpackage (injected into the data.table):Source: https://github.com/jangorecki/dtq/blob/master/R/zzz.R
aryoda commentedon Jul 10, 2017
This is a (partial?) duplicate of the older #778
[-][Request] Allow locking or protecting a data.table from any modifications[/-][+]Allow locking or protecting a data.table from any modifications[/+]MichaelChirico commentedon Apr 14, 2024
As noted in #778, I'm not sure it's possible to use the
lockBinding()mechanism directly -- it's simply too hard to tell in general when an object is locked using the public APIs R provides (please CMIIW).However, we could still fulfill this issue with a new function like
lockTable()that has a familiar name tolockBinding()but actually works by setting an attribute thatassign()can read & respond to.This would also get around the back-compatibility flaws of the
lockBinding()approach mentioned in #778.