seankross / mario

🍄 But our princess is in another castle!
Other
21 stars 1 forks source link

incorrect results if %>% expression is assigned to a variable #31

Closed pgbovine closed 2 years ago

pgbovine commented 3 years ago
library(dplyr)
x <- Formaldehyde %>% filter(optden > 0.5) %>% slice(1)

This seems like perfectly reasonable code for someone to copy-paste in, but it gives the following incorrect and misleading trace (showing both lhs and rhs as the already-sliced table):

[
    {
      "type": "unknown",
      "code_step": "Formaldehyde %>% filter(optden > 0.5) %>% slice(1)",
      "mapping": "NA",
      "data_frame": {
        "lhs": {
          "col_names": [
            "carb",
            "optden"
          ],
          "data": [
            {
              "carb": 0.6,
              "optden": 0.538
            }
          ]
        },
        "rhs": {
          "col_names": [
            "carb",
            "optden"
          ],
          "data": [
            {
              "carb": 0.6,
              "optden": 0.538
            }
          ]
        }
      }
    }
  ]

Ideally mario would detect the assignment operator and ignore it, then focus exclusively on the pipe.

It should also work with these variants of the assignment statement:

x = Formaldehyde %>% filter(optden > 0.5) %>% slice(1)
Formaldehyde %>% filter(optden > 0.5) %>% slice(1) -> x
pgbovine commented 3 years ago

... but make sure that any fix here doesn't break the existing common use case of just having pipes with no assignment to a variable

seankross commented 2 years ago

Fixed in 18edf68