Author: pv71u98h1
Date: 2026-01-12

# The m61r Object

#### pv71u98h1

#### 2026-01-12

# Introduction

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.

# Example 1: Pipeline with 1-Step Cache

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

    # View the internal data.frame
    co2[]

    ##     Type  Treatment       foo      bar
    ## 1 Quebec nonchilled 0.1079993 3.177263
    ## 2 Quebec    chilled 0.1009081 3.177263

# Example 2: Extracting the Data Frame

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

    # Get only the data.frame and not the whole m61r object
    tmp <- co2[]

    class(tmp)

    ## [1] "data.frame"

# Example 3: Manipulation of an m61r Object

The `m61r` object mimics several data frame behaviours, such as `names()`, `dim()`, and standard subsetting.

    co2 <- m61r(CO2)
    names(co2)

    ## [1] "Plant"     "Type"      "Treatment" "conc"      "uptake"

    dim(co2)

    ## [1] 84  5

    co2[1,]

    ##   Plant   Type  Treatment conc uptake
    ## 1   Qn1 Quebec nonchilled   95     16

    co2[1:10, 1:3]

    ##    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

    co2[1, "Plant"]

    ##   Plant
    ## 1   Qn1

    str(co2)

    ## Classes 'm61r', 'environment' <environment: 0x55b058abd170>

    # Sub-assignment (temporary changes)
    co2[1, "conc"] <- 100
    co2[1,]

    ##   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 the `m61r` object with a standard `data.frame`.

## Cloning

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: 0x55b058abd170>

    str(foo)

    ## Classes 'm61r', 'environment' <environment: 0x55b055d1f050>