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

Error ... number of characters is not computable in "bytes" encoding, element 1 #81

Closed
jennybc opened this issue Oct 28, 2016 · 8 comments

Comments

@jennybc
Copy link

jennybc commented Oct 28, 2016

I'm trying to compare two lists. Sorry this not a very minimal reprex but maybe it's easy for you to spot the problem?

I'm making a package of recursive lists to use in teaching and examples. I make the list available as an R object and also as JSON (and XML). I'm comparing the source list to the list I get from importing the JSON. Was hoping to use diffObj() to see the diffs but it immediately errors.

#devtools::install_github("jennybc/repurrrsive@4d9daf6")
library(repurrrsive)
library(diffobj)
## this makes a list of GitHub users available
str(gh_users, max.level = 1)
#> List of 6
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
## also the path to the corresponding JSON
ghuj <- jsonlite::fromJSON(gh_users_json(), simplifyDataFrame = FALSE)
str(ghuj, max.level = 1)
#> List of 6
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30
#>  $ :List of 30

## try comparing the first elements of these lists
diffObj(gh_users[[1]], ghuj[[1]])
#> Error in (function (u, so, ml) : number of characters is not computable in "bytes" encoding, element 1
@jennybc
Copy link
Author

jennybc commented Oct 28, 2016

More info: diffObj() does not like NULL or named list() or ... comparing the two?

gh_users[[1]][[23]]
#> NULL
ghuj[[1]][[23]]
#> named list()

@brodieG brodieG added the bug label Oct 28, 2016
@brodieG
Copy link
Owner

brodieG commented Oct 28, 2016

Thanks for reporting. I actually just started running into this problem myself but making my example reproducible was a bit of a nightmare, so this is great. I'll look at it over the weekend. From what I could tell there is a problem somewhere with special characters and regmatches. I'm not entirely looking forward to debugging this... In my case the source seemed to be the directional quotes (e.g. d/sQuote) that R has started to use.

@brodieG
Copy link
Owner

brodieG commented Oct 28, 2016

As a workaround for now you can try diffStr instead of diffObj. There seems to be an issue with diffPrint with the current release version. diffObj runs both diffPrint and diffStr to try to figure out which one provides a more meaningful diff.

Alternatively, I was able to get this to work on the current devel version:

> devtools::install_github("brodieG/diffobj@development")
> packageVersion("diffobj")
[1] ‘0.1.5.9000’

screen shot 2016-10-28 at 10 55 25 am

Although I can't think of a reason why this issue should pop up in release but not devel. Finally, I know I have recently seen the issue in the devel version as well, but apparently not with this data.

@jennybc
Copy link
Author

jennybc commented Oct 28, 2016

OK thanks for the suggestions! Yes I was using the CRAN version, I'll switch to GitHub for now.

@brodieG
Copy link
Owner

brodieG commented Oct 28, 2016

Reproducible example in development version:

library(repurrrsive)
a <- gh_users[[1]]$name
b <- sprintf("%s wow", a)
diffPrint(list(hell=a, b=NULL), list(hell=b, b=list()))
# Error in (function (u, so, ml)  : 
#  number of characters is not computable in "bytes" encoding, element 1

Note this is partly Gabor's fault for having non-ASCII characters in his name (jk).

@jennybc
Copy link
Author

jennybc commented Oct 28, 2016

Note this is partly Gabor's fault for having non-ASCII characters in his name (jk).

Why do you think I included him i this list? 😄

@brodieG
Copy link
Owner

brodieG commented Oct 29, 2016

Allright, dev version should be good to go. I'll close this issue when I merge into master. Hope to update CRAN version at some point in the next couple of weeks. Thanks for the great example.

@jennybc
Copy link
Author

jennybc commented Oct 29, 2016

Oh this is great! I've re-installed from GitHub and have successfully used diffObj() with another similar example (list1 --> JSON file --> reimport --> list2, compare list1 and list2) and it's working well. A huge help. Thanks.

@brodieG brodieG added this to the 0.1.6 milestone Nov 1, 2016
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