Skip to content

Commit

Permalink
Merge pull request #24 from parmsam/sam-dev
Browse files Browse the repository at this point in the history
Prepare release to CRAN
  • Loading branch information
parmsam authored May 1, 2024
2 parents 5b3f19a + 18df36d commit 839124f
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 34 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^docs$
^pkgdown$
^vignettes/articles$
^cran-comments\.md$
28 changes: 19 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
Package: lzstring
Type: Package
Title: An R wrapper of lzstring C++ library
Title: Wrapper for 'lz-string' C++ Library
Version: 0.1.0
Author: Sam Parmar
Maintainer: Sam Parmar <[email protected]>
Description: This package provides an R interface to the lz-string C++ library,
enabling LZ-based compression and decompression of strings directly within
R. This can be particularly useful for reducing the memory footprint of
large strings or for transmitting compressed data.
Description: Provide access to the 'lz-string' C++ library for LZ-based
compression and decompression of strings.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Expand All @@ -16,5 +12,19 @@ LinkingTo:
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
RoxygenNote: 7.2.3
URL: https://parmsam.github.io/lzstring-r/
RoxygenNote: 7.3.1
URL: https://parmsam.github.io/lzstring-r/, https://github.com/parmsam/lzstring-r
Authors@R: c(
person(
given = "Sam",
family = "Parmar",
role = c("aut", "cre"),
email = "[email protected]"
),
person(
given = "Andrey",
family = "Krasnov",
role = "cph",
comment = "Author of included lz-string C++ library"
))
BugReports: https://github.com/parmsam/lzstring-r/issues
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# lzstring 0.1.0

* Initial CRAN submission.
14 changes: 4 additions & 10 deletions R/lzstringr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ safe_decompress <- function(string, f) {
#' @return A character string representing the compressed input string in Base64 format.
#' @export
#' @examples
#' \dontrun{
#' compressToBase64("Hello, world!")
#' }
compressToBase64 <- function(string) {
stopifnot(
"`string` must be a character." = is.character(string),
Expand All @@ -101,9 +99,8 @@ compressToBase64 <- function(string) {
#' @return A character string representing the decompressed input string.
#' @export
#' @examples
#' \dontrun{
#' decompressFromBase64(compressed_string)
#' }
#' x <- compressToBase64("Hello, world!")
#' decompressFromBase64(x)
decompressFromBase64 <- function(string) {
stopifnot(
"`string` must be a character." = is.character(string),
Expand All @@ -120,9 +117,7 @@ decompressFromBase64 <- function(string) {
#' @return A character string representing the compressed input string in Encoded URI Component format.
#' @export
#' @examples
#' \dontrun{
#' compressToEncodedURIComponent("Hello, world!")
#' }
compressToEncodedURIComponent <- function(string) {
stopifnot(
"`string` must be a character." = is.character(string),
Expand All @@ -139,9 +134,8 @@ compressToEncodedURIComponent <- function(string) {
#' @return A character string representing the decompressed input string.
#' @export
#' @examples
#' \dontrun{
#' decompressFromEncodedURIComponent(compressed_string)
#' }
#' x <- compressToEncodedURIComponent("Hello, world!")
#' decompressFromEncodedURIComponent(x)
decompressFromEncodedURIComponent <- function(string) {
stopifnot(
"`string` must be a character." = is.character(string),
Expand Down
6 changes: 6 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ The goal of lzstring-r is to provide an R wrapper for the [lzstring C++ library]

## Installation

You can install the released version of lzstringr from CRAN with:

``` r
install.packages("lzstringr")
```

You can install the development version of lzstringr from [GitHub](https://github.com/) with:

``` r
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ lzstring in JavaScript—peek at his work over

## Installation

You can install the released version of lzstringr from CRAN with:

``` r
install.packages("lzstringr")
```

You can install the development version of lzstringr from
[GitHub](https://github.com/) with:

Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
2 changes: 0 additions & 2 deletions man/compressToBase64.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/compressToEncodedURIComponent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/decompressFromBase64.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/decompressFromEncodedURIComponent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions vignettes/articles/performance.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ generate_random_string <- function(length) {
}
# Prepare a data frame to store benchmark results
benchmark_results <- data.frame(length_str = numeric(), comp_time = numeric(), decomp_time = numeric())
benchmark_results <- data.frame(raw_len = numeric(), comp_len = numeric(),comp_time = numeric(), decomp_time = numeric())
# Run benchmark for each string length
for (i in 1:100) {
Expand All @@ -39,19 +39,31 @@ for (i in 1:100) {
decomp_time_tmp <- as.numeric(decomp$median)
comp_time_tmp <- as.numeric(comp$median)
# Store the median time and string length
benchmark_results <- rbind(benchmark_results, data.frame(length_str = nchar(big_str), comp_time = comp_time_tmp, decomp_time = decomp_time_tmp))
benchmark_results <- rbind(benchmark_results, data.frame(raw_len = nchar(big_str), comp_len = nchar(comp$result), comp_time = comp_time_tmp, decomp_time = decomp_time_tmp))
}
# Convert time to milliseconds
benchmark_results$comp_time <- benchmark_results$comp_time * 1000
benchmark_results$decomp_time <- benchmark_results$decomp_time * 1000
```

Let's plot the compression ratio for each string length. Compression ratio is the ratio between the length of the raw string to the length of the compressed string. These ratios are not good because the strings we're producing are random and not very compressible, but they're good for testing compression and decompression times.

```{r plot-size-results, fig.width = 7, fig.asp = 0.6}
benchmark_results$compression_ratio <- benchmark_results$raw_len / benchmark_results$comp_len
ggplot(benchmark_results) +
geom_line(aes(x = raw_len, y = compression_ratio)) +
labs(x = "String length (characters)",
y = "Compression Ratio") +
theme_minimal() +
theme(legend.position = "bottom")
```

Now let's plot the results for compression and decompression times of all those strings we created.

```{r plot-results, fig.width = 7, fig.asp = 0.6}
```{r plot-time-results, fig.width = 7, fig.asp = 0.6}
ggplot(benchmark_results) +
geom_line(aes(x = length_str, y = comp_time, col = "Compression"), ) +
geom_line(aes(x = length_str, y = decomp_time, col = "Decompression")) +
geom_line(aes(x = raw_len, y = comp_time, col = "Compression"), ) +
geom_line(aes(x = raw_len, y = decomp_time, col = "Decompression")) +
labs(x = "String length (characters)",
y = "Time (milliseconds)") +
theme_minimal() +
Expand Down

0 comments on commit 839124f

Please sign in to comment.