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

formal argument "indent" matched by multiple actual arguments #97

Closed
martinstuder opened this issue Apr 22, 2015 · 6 comments
Closed

formal argument "indent" matched by multiple actual arguments #97

martinstuder opened this issue Apr 22, 2015 · 6 comments

Comments

@martinstuder
Copy link

In jsonlite 0.9.15 toJSON(1, indent = NA) produces the expected output [1].

In version 0.9.16 the same errors with:

Error in .local(x, ...) : 
  formal argument "indent" matched by multiple actual arguments
@jeroen
Copy link
Owner

jeroen commented Apr 22, 2015

Why are you passing the indent argument to toJSON? What are you trying to achieve?

@martinstuder
Copy link
Author

This is to what I have reduced the problem to. I'm not using indent anywhere explicitly so I was assuming it must originate from jsonlite. Let me dig deeper if that's not the case.

@martinstuder
Copy link
Author

Ok, after investigating further, here a more complete example of what I'm trying to do:

require(jsonlite)

setOldClass("boxed")

# See also https://github.com/jeroenooms/jsonlite/issues/62
asJSON = jsonlite:::asJSON

setMethod("asJSON", "boxed", function(x, ...) {
  args = list(...)
  args$auto_unbox = FALSE
  do.call(toJSON, c(list(unclass(x)), args))
})

boxed = function(x) {
  class(x) = c("boxed", class(x))
  x
}

toJSON(boxed(1), auto_unbox = TRUE)

For communication with a web service I generally need unboxed values except for a few rare cases. For this purpose I introduced the boxed class and a corresponding asJSON method.

As I understand, extending asJSON/toJSON is currently under discussion in #62. The above used to work fine in jsonlite 0.9.15 but fails with the mentioned error in jsonlite 0.9.16.

@jeroen
Copy link
Owner

jeroen commented Apr 23, 2015

We have a native argument for that now. See #78. You should probably use this.

The bug appears because within your asJSON function you should be calling asJSON instead of toJSON. But this is a great example why exposing asJSON might not be a good idea. @yihui.

@yihui
Copy link

yihui commented Apr 24, 2015

  1. toJSON(auto_unbox=TRUE, force=TRUE) should not unbox objects wrapped in I() #78 is so much more elegant than the hack here (it looks users are more likely to desire auto_unbox = TRUE than FALSE, and I() is much cheaper than jsonlite::unbox() or the boxed class here);
  2. Unfortunately, I'm thinking of the opposite: the hack here is yet another piece of evidence that you should open the door of asJSON instead of letting users jsonlite:::asJSON, which smells bad;

I don't know quite understand why this is a great example. I see it as a hack out of desperation since users do not have your blessings and have to turn to the dark force.

@jeroen
Copy link
Owner

jeroen commented Apr 24, 2015

Closing this, @martinstuder just use I() instead of boxed().

@jeroen jeroen closed this as completed Apr 24, 2015
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

3 participants