You could assign
and then stop
. It throws an error, but stops the evaluation:
result <-
mtcars |>
filter(cyl == 4) |>
assign(x = "early") |>
stop() |>
group_by(gear) |>
summarise()
#Error in group_by(stop(assign(filter(mtcars, cyl == 4), x = "early")), :
# c(22.8, 24.4, 22.8, 32.4, 30.4, 33.9, 21.5, 27.3, 26, 30.4, 21.4)c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4)c(108, 146.7, 140.8, 78.7, 75.7, 71.1, 120.1, 79, 120.3, 95.1, 121)c(93, 62, 95, 66, 52, 65, 97, 66, 91, 113, 109)c(3.85, 3.69, 3.92, 4.08, 4.93, 4.22, 3.7, 4.08, 4.43, 3.77, 4.11)c(2.32, 3.19, 3.15, 2.2, 1.615, 1.835, 2.465, 1.935, 2.14, 1.513, 2.78)c(18.61, 20, 22.9, 19.47, 18.52, 19.9, 20.01, 18.9, 16.7, 16.9, 18.6)c(1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)c(1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1)c(4, 4, 4, 4, 4, 4, 3, 4, 5, 5, 4)c(1, 2, 2, 1, 2, 1, 1, 1, 2, 2, 2)
#> result
#Error: object 'result' not found
#> early
# mpg cyl disp hp drat wt qsec vs am gear carb
#Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
#Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
#Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
#Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
#Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
#Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
#Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
#Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
#Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
#Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
#Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2