The m61r object is a lightweight container that enables
all the functions present in the package while providing a fluent
“pipeline” interface.
The primary goal of this package is to provide a powerful, zero-dependency grammar for data manipulation in pure Base R.
The m61r object maintains an internal state. When you
call methods like filter, mutate, or
summarise, the object is updated in place, allowing you to
chain operations efficiently.
co2 <- m61r(CO2)
co2$filter(~Plant %in% c("Qn1", "Qc3"))
co2$mutate(z1 = ~uptake/conc, y = ~conc/100)
co2$group_by(~c(Type, Treatment))
co2$summarise(foo = ~mean(z1), bar = ~sd(y))
co2$head()## Type Treatment foo bar
## 1 Quebec nonchilled 0.1079993 3.177263
## 2 Quebec chilled 0.1009081 3.177263
## Type Treatment foo bar
## 1 Quebec nonchilled 0.1079993 3.177263
## 2 Quebec chilled 0.1009081 3.177263
If you need to return to a standard R workflow, you can extract the
internal data frame at any time using the [] operator.
co2 <- m61r(CO2)
co2$filter(~Plant %in% c("Qn1", "Qc3"))
co2$transmutate(z1 = ~uptake/conc, y = ~conc/100)
co2$head()## z1 y
## 1 0.16842105 0.95
## 2 0.17371429 1.75
## 3 0.13920000 2.50
## 4 0.10628571 3.50
## 5 0.07060000 5.00
## 6 0.05807407 6.75
## [1] "data.frame"
The m61r object mimics several data frame behaviours,
such as names(), dim(), and standard
subsetting.
## [1] "Plant" "Type" "Treatment" "conc" "uptake"
## [1] 84 5
## Plant Type Treatment conc uptake
## 1 Qn1 Quebec nonchilled 95 16
## Plant Type Treatment
## 1 Qn1 Quebec nonchilled
## 2 Qn1 Quebec nonchilled
## 3 Qn1 Quebec nonchilled
## 4 Qn1 Quebec nonchilled
## 5 Qn1 Quebec nonchilled
## 6 Qn1 Quebec nonchilled
## 7 Qn1 Quebec nonchilled
## 8 Qn2 Quebec nonchilled
## 9 Qn2 Quebec nonchilled
## 10 Qn2 Quebec nonchilled
## Plant
## 1 Qn1
## Classes 'm61r', 'environment' <environment: 0x5cc26eff5b50>
## Plant Type Treatment conc uptake
## 1 Qn1 Quebec nonchilled 100 16
Warning: Be careful when re-assigning the object itself. Always use the methods or brackets for manipulation. If you perform
co2 <- co2[-1,], you will replace them61robject with a standarddata.frame.
Because m61r objects are built on R environments, a
simple assignment (foo <- co2) creates a reference to
the same data. To create a completely independent copy,
use the $clone() method.
# Cloning into a new environment
foo <- co2$clone()
# Verify they are distinct objects in memory
str(co2)## Classes 'm61r', 'environment' <environment: 0x5cc26eff5b50>
## Classes 'm61r', 'environment' <environment: 0x5cc2700f0160>