Closed jcheng5 closed 4 years ago
with_qfuns doesn't find objects in the calling environment, only objects in qry_funs or the base environment.
with_qfuns
qry_funs
library(patentsview) create_query <- function(date_of_patent) { with_qfuns( and( gte(patent_date = date_of_patent), text_phrase(patent_abstract = c("computer program")), or( eq(inventor_last_name = "ihaka"), eq(inventor_first_name = "chris") ) ) ) } create_query("2007-01-01") #> Error in gte(patent_date = date_of_patent): object 'date_of_patent' not found
Created on 2020-03-24 by the reprex package (v0.3.0)
This alternate implementation of with_qfuns solves it:
with_qfuns <- function(code, envir = parent.frame()) { eval(substitute(code), qry_funs, envir) } create_query("2007-01-01") #> {"_and":[{"_gte":{"patent_date":"2007-01-01"}},{"_text_phrase":{"patent_abstract":"computer program"}},{"_or":[{"_eq":{"inventor_last_name":"ihaka"}},{"_eq":{"inventor_first_name":"chris"}}]}]}
Thanks!
with_qfuns
doesn't find objects in the calling environment, only objects inqry_funs
or the base environment.Created on 2020-03-24 by the reprex package (v0.3.0)
This alternate implementation of
with_qfuns
solves it: