There are one or more ways to lock or preserve data.table
, none Now they can be modified?
Say we have data:
DT < After this I get the following behavior: dt < Can I modify / code>? # Error or warning: DT # ID Val # 1: 1FU ##Uncategorized
dt [, val: = "bar"] # H2> It came because I am the author, a small R package at work which uses data.table
on a large scale. It has some data.tables
Translation tables), which may be the cause of issues (inappropriate translation) when a user accidentally modified it. I expected the data to be "internal" (as defined), but it does not.
Because it is only a problem with the data.table
object, I just use the data according to the requirement within the function. Use frames, copying + casting Use data.table
if I need I will go this route (my tables are small enough that time / memory overhead will not be seen), but I hope there is a more natural solution.
dt [, val: = "bar"] # H2> It came because I am the author, a small R package at work which uses data.table
on a large scale. It has some data.tables
Translation tables), which may be the cause of issues (inappropriate translation) when a user accidentally modified it. I expected the data to be "internal" (as defined), but it does not.
Because it is only a problem with the data.table
object, I just use the data according to the requirement within the function. Use frames, copying + casting Use data.table
if I need I will go this route (my tables are small enough that time / memory overhead will not be seen), but I hope there is a more natural solution.
Here are some possible suggestions.
You can write your wrapper object (possibly using R6 package) which defines all edits to give an error to the device and do not change the underlying data, but the object Uses usable use functionality of standard data to read.
You can follow the approach of petals
TeachingDemos function in package.
Both of the above are not correct and a determined person can still change them, they may not even be worth the work.
Every time your function runs, you can re-read your tables so that there is no need to change the disc, only r
There are tools / packages to calculate things like MD5sums, so that you can calculate for your data. Qualified, then when code runs, you can check MD5sum and close it.
You can save data data in RDTa style file and attach the file to the search path instead of loading it in the work directory. It can still be changed, but the chances of getting less than the spot are less and it will require more effort to change (make sure your code does not use local copies in the global environment ( get Use
or ::
or check that the local copy does not exist)).
No comments:
Post a Comment