This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 57a56040 fix(r): stabilize array buffer printing (#1007)
57a56040 is described below

commit 57a56040cb48b19d683a5c921ff044f2bab014f3
Author: Dewey Dunnington <[email protected]>
AuthorDate: Thu Nov 5 09:39:42 2026 -0800

    fix(r): stabilize array buffer printing (#1007)
    
    R-devel now inserts a space between list labels and values whose `str()`
    methods print their own output. Normalize the captured array proxy
    output to that format on older R versions, keeping array buffer printing
    stable across supported R releases. Update the string-view array
    snapshot accordingly.
    
    ```r
    library(nanoarrow)
    array <- as_nanoarrow_array(letters, schema = na_string_view())
    print(array)
    #> <nanoarrow_array string_view[26]>
    #>  $ length    : int 26
    #>  $ null_count: int 0
    #>  $ offset    : int 0
    #>  $ buffers   : List of 3
    #>   ..$ : <nanoarrow_buffer validity<bool>[null] ``
    #>   ..$ : <nanoarrow_buffer data<string_view>[26][416 b]>`
    #>   ..$ : <nanoarrow_buffer variadic_size<int64>[null] ``
    #>  $ dictionary: NULL
    #>  $ children  : list()
    ```
---
 r/R/array.R                      |  4 ++++
 r/tests/testthat/_snaps/array.md | 18 +++++++++---------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/r/R/array.R b/r/R/array.R
index 2aabaf09..bc028b6f 100644
--- a/r/R/array.R
+++ b/r/R/array.R
@@ -87,6 +87,10 @@ str.nanoarrow_array <- function(object, ...) {
     # line of the output ("List of 6")
     info <- nanoarrow_array_proxy_safe(object)
     raw_str_output <- utils::capture.output(str(info, ...))
+    # R < 4.7 omitted the space between a list label and an object whose
+    # str() method handled its own output. Normalize to the current format so
+    # array printing is consistent across supported R versions.
+    raw_str_output <- sub("(?<=\\s):(?=\\S)", ": ", raw_str_output, perl = 
TRUE)
     cat(paste0(raw_str_output[-1], collapse = "\n"))
     cat("\n")
   }
diff --git a/r/tests/testthat/_snaps/array.md b/r/tests/testthat/_snaps/array.md
index ccc2d1ef..1eb4c013 100644
--- a/r/tests/testthat/_snaps/array.md
+++ b/r/tests/testthat/_snaps/array.md
@@ -7,10 +7,10 @@
        $ length    : int 26
        $ null_count: int 0
        $ offset    : int 0
-       $ buffers   :List of 3
-        ..$ :<nanoarrow_buffer validity<bool>[null] ``
-        ..$ :<nanoarrow_buffer data<string_view>[26][416 b]>`
-        ..$ :<nanoarrow_buffer variadic_size<int64>[null] ``
+       $ buffers   : List of 3
+        ..$ : <nanoarrow_buffer validity<bool>[null] ``
+        ..$ : <nanoarrow_buffer data<string_view>[26][416 b]>`
+        ..$ : <nanoarrow_buffer variadic_size<int64>[null] ``
        $ dictionary: NULL
        $ children  : list()
 
@@ -23,11 +23,11 @@
        $ length    : int 1
        $ null_count: int 0
        $ offset    : int 0
-       $ buffers   :List of 4
-        ..$ :<nanoarrow_buffer validity<bool>[null] ``
-        ..$ :<nanoarrow_buffer data<string_view>[1][16 b]>`
-        ..$ :<nanoarrow_buffer variadic_data<string>[35 b]> `this string is 
longer...`
-        ..$ :<nanoarrow_buffer variadic_size<int64>[1][8 b]> `35`
+       $ buffers   : List of 4
+        ..$ : <nanoarrow_buffer validity<bool>[null] ``
+        ..$ : <nanoarrow_buffer data<string_view>[1][16 b]>`
+        ..$ : <nanoarrow_buffer variadic_data<string>[35 b]> `this string is 
longer...`
+        ..$ : <nanoarrow_buffer variadic_size<int64>[1][8 b]> `35`
        $ dictionary: NULL
        $ children  : list()
 

Reply via email to