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 spread_values functions to work with unquoted paths #26

Closed
jeremystan opened this issue Aug 28, 2016 · 4 comments
Closed

Allow spread_values functions to work with unquoted paths #26

jeremystan opened this issue Aug 28, 2016 · 4 comments

Comments

@jeremystan
Copy link
Collaborator

The following works:

'{"key": "value"}' %>% spread_values(key = jstring("key"))
#>   document.id   key
#> 1           1 value

but this does not:

'{"key": "value"}' %>% spread_values(key = jstring(key))
#> Error in as_function(.f, ...) : object 'key' not found
@jeremystan
Copy link
Collaborator Author

This should work with enter_object as well:

# works
'{"k1": {"k2": "value"}}' %>% enter_object("k1")
# should also work
'{"k1": {"k2": "value"}}' %>% enter_object(k1)

@jeremystan
Copy link
Collaborator Author

Looks like we can use the final NSE Dot-dot-dot section here to do this:
https://cran.r-project.org/web/packages/lazyeval/vignettes/lazyeval.html

jeremystan pushed a commit that referenced this issue Aug 31, 2016
jeremystan pushed a commit that referenced this issue Aug 31, 2016
jeremystan pushed a commit that referenced this issue Aug 31, 2016
…pture because it failed if the path was the name of a global function!!!
@jeremystan
Copy link
Collaborator Author

Hadley's suggestion of

library(purrr)

# Create a JSON path with a minimum of typing
path <- function(...) {
  dots <- dots(...)

  if (!every(dots, is.name)) {
    stop("Path components must be single names", call. = FALSE)
  }

  structure(
    map_chr(dots, as.character),
    class = "path"
  )
}

dots <- function(...) {
  eval(substitute(alist(...)))
}

path(a, b, c)

is working great with minor modifications!

@jeremystan
Copy link
Collaborator Author

jeremystan commented Sep 17, 2016

Need to:

  • Use in all other functions
  • Change documentation to be predominantly unquoted
  • Change vignettes to be unquoted
  • Update NEWS and README
  • Improve documentation of path itself (and question why it is exported)
  • Thank Hadley!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant