Not sure if this is along the lines that you were hoping for, but I translated your code into a version that I understand better, and thought I'd see if it helps:
library(tidyverse)
library(rlang)
#>
#> Attaching package: 'rlang'
#> The following objects are masked from 'package:purrr':
#>
#> %@%, as_function, flatten, flatten_chr, flatten_dbl,
#> flatten_int, flatten_lgl, flatten_raw, invoke, list_along,
#> modify, prepend, splice
twotimer2 <- function(df, col1, col2, col3){
col1 <- enexpr(col1)
col2 <- enexpr(col2)
col3 <- enexpr(col3)
sm_df_call <- expr(df %>% smalldf2(!!col1, !!col2, !!col3))
iterations <- eval(sm_df_call)
list(iterations = iterations, col3value = as_name(col3))
}
smalldf2 <- function(dff, col1, col2, col3){
col1 <- enexpr(col1)
col2 <- enexpr(col2)
col3 <- enexpr(col3)
newdff_call <- expr(dff %>% select(!!col1, !!col2, !!col3))
newdff <- eval(newdff_call)
yacol2value <- NULL; try(yacol2value <- rlang::as_name(col2)) # error captured by try()
newerdff <- NULL
try(newerdff <- newdff %>%
pivot_longer(-Model, names_to = rlang::as_name(col3), values_to = "value")) # error captured by try()
newname <- names(newdff)[3]
thishackworks <- newdff %>%
pivot_longer(-!!col1, names_to = newname, values_to = "value")
list(newdff = head(newdff), newerdff = head(newerdff), col1value = as_name(col1), col2value = as_name(col2),
yacol2value = yacol2value, newname = newname, thishackworks = head(thishackworks))
}
mtcars %>% head() %>%
as_tibble(rownames = "Model") %>%
twotimer2(Model, cyl, carb)
#> $iterations
#> $iterations$newdff
#> # A tibble: 6 x 3
#> Model cyl carb
#> <chr> <dbl> <dbl>
#> 1 Mazda RX4 6 4
#> 2 Mazda RX4 Wag 6 4
#> 3 Datsun 710 4 1
#> 4 Hornet 4 Drive 6 1
#> 5 Hornet Sportabout 8 2
#> 6 Valiant 6 1
#>
#> $iterations$newerdff
#> # A tibble: 6 x 3
#> Model carb value
#> <chr> <chr> <dbl>
#> 1 Mazda RX4 cyl 6
#> 2 Mazda RX4 carb 4
#> 3 Mazda RX4 Wag cyl 6
#> 4 Mazda RX4 Wag carb 4
#> 5 Datsun 710 cyl 4
#> 6 Datsun 710 carb 1
#>
#> $iterations$col1value
#> [1] "Model"
#>
#> $iterations$col2value
#> [1] "cyl"
#>
#> $iterations$yacol2value
#> [1] "cyl"
#>
#> $iterations$newname
#> [1] "carb"
#>
#> $iterations$thishackworks
#> # A tibble: 6 x 3
#> Model carb value
#> <chr> <chr> <dbl>
#> 1 Mazda RX4 cyl 6
#> 2 Mazda RX4 carb 4
#> 3 Mazda RX4 Wag cyl 6
#> 4 Mazda RX4 Wag carb 4
#> 5 Datsun 710 cyl 4
#> 6 Datsun 710 carb 1
#>
#>
#> $col3value
#> [1] "carb"
Created on 2020-03-19 by the reprex package (v0.3.0)