Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow parameter inequalities in R syntax in addition to API syntax #14

Open
potterzot opened this issue Jul 24, 2019 · 2 comments
Open

Comments

@potterzot
Copy link
Contributor

The API uses:

  • __LE = <=
  • __LT = <
  • __GT = >
  • __GE = >=
  • __LIKE = like
  • __NOT_LIKE = not like
  • __NE = not equal

appended to the parameter name to allow for inequalities. It would be nice is users could specify year >= 2012 and have that be translated into year__GE = 2012 in the query.

@rdinter
Copy link
Contributor

rdinter commented Dec 2, 2019

For the conditional year values, I'd suggest looking at lines 85-114 of utils in usdarnass (https://github.com/rdinter/usdarnass/blob/master/R/utils.R):

# Conditional year values
conditional_years <- function(x) {
  # Check to see if year used a logical operator
  years <- trimws(x)
  punct <- grepl("[[:punct:]]", years)
  punct_years <- as.numeric(gsub("[[:punct:]]", "", years))
  
  # Conditional year values
  # __LE = <= 
  # __LT = < 
  # __GT = > 
  # __GE = >= 
  # __LIKE = like 
  # __NOT_LIKE = not like 
  # __NE = not equal 
  year     <- punct_years[!punct]
  year__LE <- punct_years[(grepl("^=<|^<=", years) | grepl("=>$|>=$", years))]
  year__LT <- punct_years[((grepl("^<", years) | grepl(">$", years)) &
                             !grepl("=", years))]
  year__GE <- punct_years[(grepl("^=>|^>=", years) | grepl("=<$|<=$", years))]
  year__GT <- punct_years[((grepl("^>", years) | grepl("<$", years)) &
                             !grepl("=", years))]
  
  results <- list(year = year,
                  year__LE = year__LE,
                  year__LT = year__LT,
                  year__GE = year__GE,
                  year__GT = year__GT)
  return(results)
}

Basically treat the argument for year as a character and search through for punctuation that might be at the beginning or end.

One issue is that the API is finicky if you want to use multiple conditionals to create a range of year values. The API seems to only take the first conditional related to year as the subset rdinter/usdarnass#3

@potterzot
Copy link
Contributor Author

@rdinter thanks for this as well! Hopefully I'll get to tackle this sometime soon.

@potterzot potterzot added this to the Version 0.6 release milestone Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants