-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add functions to encode and decode shinylive URLs #70
Comments
The encoding and decoding requires the lzstring library, but as far as I can tell, there's not an lzstring implementation for R. Here are some possibilities, although any of them will take some effort:
|
Put together a wrapper based on your PR in an R package here. This is my first time using {cpp11} so I might've missed a few things. Some of the unit tests I added might be helpful. Note that there was one unit test that I was unable to port over from the C++ library over to the R package here. Would be curious to hear your thoughts about handling that case. |
Great! Are you planning on submitting the package to CRAN and maintain it in the future? Some thoughts:
|
Thanks! Fixed the unit test and added a condition into the exported functions to ensure UTF-8 encoding in the string being passed through. I see what you mean. Looks like the |
Instead of throwing if the string is not UTF-8, I think you should use I don't know the details of what exactly was removed in C++20. As of R 4.0, the minimum C++ version that is supported is C++11, so this will have to work on C++11 through C++20. I think the existing code is OK on C++11 and 14, and you'll need a different strategy for C++17 and 20. And of course you'll have to do something for Windows. (You should be able to use Github Actions to test on Windows.) I definitely think you should not switch to Rcpp. Rcpp has been around for longer and cpp11 supports newer C++ features than Rcpp. The minimum C++ version for cpp11 is C++11, but it will work with newer versions as well. cpp11 is also a lighter-weight dependency. See https://github.com/r-lib/cpp11/?tab=readme-ov-file#motivations |
You're right. Unfortunately, it looks like
I haven't identified a drop in replacement for UTF-8 to UTF-16 conversion and vis-versa in C++ yet. There doesn't seem to be an easy fix for it. |
I think you might be able to use R's iconv("abcdefg", from="UTF-8", to="UTF-16", toRaw=TRUE)
#> [[1]]
#> [1] fe ff 00 61 00 62 00 63 00 64 00 65 00 66 00 67
iconv("abcdefg", from="UTF-8", to="UTF-16LE", toRaw=TRUE)
#> [[1]]
#> [1] 61 00 62 00 63 00 64 00 65 00 66 00 67 00
iconv("abcdefg", from="UTF-8", to="UTF-16BE", toRaw=TRUE)
#> [[1]]
#> [1] 00 61 00 62 00 63 00 64 00 65 00 66 00 67 Maybe you can encode it as UTF-16 with BOM in R, then send it in to the function as a raw vector, then in C++ convert that to a UTF-16 string. I asked Claude AI to come up with some code for the C++ side and posted it here: |
Great news! The checks for nearly all of the operating systems in the GH check standard workflow are passing now (except macOS-latest). have merged to my main branch and updated my R-CMD-check to point to the same one used in this repo: parmsam/lzstring-r#4 |
Good progress! A few thing I noticed when I took a quick look:
|
First of all, I really appreciate the collaboration that's occurring here in this thread! I think there's a lot of value in bringing the I don't want to get in the way or forestall the progress being made on that front. That said, I had done some work on this already using the original lz-string.js implementation called via V8. With this approach, performing the lzstring compression/decompression is quite easy and is performant, at least in my testing so far. I've put the work into the feat/encode-decode-url branch, along with a proof-of-concept We could easily start with this approach and replace the encoding/decoding step with functions from |
Thanks for sharing that @gadenbuie. That's awesome that the JS version works via V8. Expanded the unit tests and switched over to the standard GH workflow. I had problems converting the UTF-16 integer vector that had null bytes due to spaces into a raw vector. Here's an example after I compressed using
On the topic of different operating systems, not sure what to do about a |
@gadenbuie / @wch is there a reason for needing a custom R implementation? Why not directly embed |
We don't necessarily need a custom lzstring implementation (although it'd be nice to have one) but we do need to be able to call lzstring from R. The goal of this feature request is to provide a method that (from R) composes a shinylive.io URL for an app comprised of local files. It's confusing because we use "shinylive" for several different contexts. The context here is local files → R → shinylive.io |
@wch / @gadenbuie lzstring is on CRAN now: https://cran.r-project.org/web/packages/lzstring/index.html |
Similar to the Python feature that was added in 0.2.0, please consider adding shinylive URL encode and shinylive URL decode R functions to encode local apps into a shinylive.io URL or decode a shinylive.io URL into local files.
The text was updated successfully, but these errors were encountered: