1

I am trying to create an immutable data-frame in R. Something like

df = iris
df = make_immutable(df)

df = df[1:100,] #gives error because df is now immutable

Is there any such function in R, like make_immutable, which can restrict an R object from further modifications during the session?

Context: I have a machine learning pipeline which has a component written by a fellow developer who is modifying a data-frame in-place at multiple places. I want to restrict the modification of this data frame after some point. Any help is highly appreciated.

penguin
  • 1,267
  • 14
  • 27
  • 3
    Does this answer your question? [Declaring a Const Variable in R](https://stackoverflow.com/questions/936748/declaring-a-const-variable-in-r) – Clemsang Feb 07 '20 at 08:08
  • 2
    Yes. `lockBinding("df", .GlobalEnv)` works. Thank you @Clemsang. – penguin Feb 07 '20 at 08:18

0 Answers0