I have a sql table set up via dplyr like this:
num gameday_link stand b_height px pz type
1 1 gid_2016_04_05_houmlb_nyamlb_1 R 5-6 0.194 3.225 B
2 1 gid_2016_04_05_houmlb_nyamlb_1 R 5-6 0.510 1.965 S
3 1 gid_2016_04_05_houmlb_nyamlb_1 R 5-6 -1.367 2.459 B
What I would like to do is add an additional column called correct, which holds the T or F results of a custom function called isCallCorrectV. The parameters of isCallCorrectV are columns in the table.
Here is an example of isCallCorrectV in action:
> isCallCorrectV(c(0.0, 2.5), c(2.5, 0), c("S", "B"), c("6-0", "5-0"), c("R", "L"))
[1] TRUE FALSE
I tried using this command, but I get an error.
dplyr::mutate(noswings, correct = isCallCorrectV(px, pz, type, b_height, stand))
Error in sqliteSendQuery(conn, statement) :
error in statement: no such function: ISCALLCORRECTV
dplyrknows how to convert to SQL (andisCallCorrectisn't on that list).isCallCorrectis made up of only those functions then you could potentially write it out long-form insidemutate()to get your desired result. That won't be very friendly, and since your function calls another custom function that callsldplyI'm going to say it's not an option here.dplyr, whatdplyris doing for you is translating R syntax to SQL syntax. When you start using custom functionsdplyrjust tries to call them. If you're working in R and calling R functions, everything's great. If you're working in SQL and calling SQL functions, everything's great. Butdplyrcan't translate arbitrary R code to SQL, so your custom functions need to match the back-end language (and be defined on the back-end).