Error in .f(.x[[i]], ...) : object 'Birzai' not found

Hello,
I am trying to use the following function:
f<-function(x, y){
a<-select(x, y)
return(a)
}

f(sniegas, Birzai)

for me, this function looks okay, but when I try to run it with a variables "f(sniegas, Birzai)" I receive this error "Error in .f(.x[[i]], ...) : object 'Birzai' not found". Does anyone know why this error appear?
Thanks in advance :slight_smile:

1 Like

You have to use tidy evaluation

library(dplyr)
library(rlang)

f <- function(x, y) {
    a <- select(x, {{y}})
    return(a)
}

f(iris, Sepal.Length)
#>     Sepal.Length
#> 1            5.1
#> 2            4.9
#> 3            4.7
#> 4            4.6
#> 5            5.0
#> 6            5.4
#> 7            4.6
#> 8            5.0
#> 9            4.4
#> 10           4.9
#> 11           5.4
#> 12           4.8
#> 13           4.8
#> 14           4.3
#> 15           5.8
#> 16           5.7
#> 17           5.4
#> 18           5.1
#> 19           5.7
#> 20           5.1
#> 21           5.4
#> 22           5.1
#> 23           4.6
#> 24           5.1
#> 25           4.8
#> 26           5.0
#> 27           5.0
#> 28           5.2
#> 29           5.2
#> 30           4.7
#> 31           4.8
#> 32           5.4
#> 33           5.2
#> 34           5.5
#> 35           4.9
#> 36           5.0
#> 37           5.5
#> 38           4.9
#> 39           4.4
#> 40           5.1
#> 41           5.0
#> 42           4.5
#> 43           4.4
#> 44           5.0
#> 45           5.1
#> 46           4.8
#> 47           5.1
#> 48           4.6
#> 49           5.3
#> 50           5.0
#> 51           7.0
#> 52           6.4
#> 53           6.9
#> 54           5.5
#> 55           6.5
#> 56           5.7
#> 57           6.3
#> 58           4.9
#> 59           6.6
#> 60           5.2
#> 61           5.0
#> 62           5.9
#> 63           6.0
#> 64           6.1
#> 65           5.6
#> 66           6.7
#> 67           5.6
#> 68           5.8
#> 69           6.2
#> 70           5.6
#> 71           5.9
#> 72           6.1
#> 73           6.3
#> 74           6.1
#> 75           6.4
#> 76           6.6
#> 77           6.8
#> 78           6.7
#> 79           6.0
#> 80           5.7
#> 81           5.5
#> 82           5.5
#> 83           5.8
#> 84           6.0
#> 85           5.4
#> 86           6.0
#> 87           6.7
#> 88           6.3
#> 89           5.6
#> 90           5.5
#> 91           5.5
#> 92           6.1
#> 93           5.8
#> 94           5.0
#> 95           5.6
#> 96           5.7
#> 97           5.7
#> 98           6.2
#> 99           5.1
#> 100          5.7
#> 101          6.3
#> 102          5.8
#> 103          7.1
#> 104          6.3
#> 105          6.5
#> 106          7.6
#> 107          4.9
#> 108          7.3
#> 109          6.7
#> 110          7.2
#> 111          6.5
#> 112          6.4
#> 113          6.8
#> 114          5.7
#> 115          5.8
#> 116          6.4
#> 117          6.5
#> 118          7.7
#> 119          7.7
#> 120          6.0
#> 121          6.9
#> 122          5.6
#> 123          7.7
#> 124          6.3
#> 125          6.7
#> 126          7.2
#> 127          6.2
#> 128          6.1
#> 129          6.4
#> 130          7.2
#> 131          7.4
#> 132          7.9
#> 133          6.4
#> 134          6.3
#> 135          6.1
#> 136          7.7
#> 137          6.3
#> 138          6.4
#> 139          6.0
#> 140          6.9
#> 141          6.7
#> 142          6.9
#> 143          5.8
#> 144          6.8
#> 145          6.7
#> 146          6.7
#> 147          6.3
#> 148          6.5
#> 149          6.2
#> 150          5.9

Created on 2019-11-23 by the reprex package (v0.3.0.9000)

Thank you very much it worked :slight_smile: :slight_smile:

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.