You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add the R generic "toString" to "jobjRef" methods #348
This is a feature request:
Sometimes I use to add a method for "jobjRef" to the generic base R toString(x, ...) and map it to java's object toString
It can made possible to use the |> pipe and otherwise save code or prevent the use of reflection for such a basic action as x$toString()
Good idea, but I think it may be more R-like to simply use the as.character generic for this instead (which is currently unimplemented) - I'd rather not introduce a new generic unless it is required. That said, there is a slight difference in Java's toString() notion in that as.character is vectorized, so one may think of arrays behaving differently between as.character and toString.
Yes, as.character seems natural and automatically works with other R functions such as paste.
On the other hand, R has a generic toString since 1.2 (probably a concept borrowed from Java). The default uses paste to concatenate vectors to a length one output, the manpages describes this single element semantics explicitly:
This is a helper function for [format] to produce a single character string describing an R object.
However the default does not use format at all, but as.character through paste coercing of its argument...
However it should be noted that java object arrays (not from primitive types) are more akin of lists, and as.character over lists does not dispatch any generic (not sure)...
Activity
s-u commentedon May 16, 2026
Good idea, but I think it may be more R-like to simply use the
as.charactergeneric for this instead (which is currently unimplemented) - I'd rather not introduce a new generic unless it is required. That said, there is a slight difference in Java'stoString()notion in thatas.characteris vectorized, so one may think of arrays behaving differently betweenas.characterandtoString.rikivillalba commentedon May 17, 2026
Yes,
as.characterseems natural and automatically works with other R functions such aspaste.On the other hand, R has a generic
toStringsince 1.2 (probably a concept borrowed from Java). The default usespasteto concatenate vectors to a length one output, the manpages describes this single element semantics explicitly:However the default does not use
formatat all, butas.characterthroughpastecoercing of its argument...One may think in separate methods for jarrayRef and jobjRef to obey to the vector nature of
as.character:However it should be noted that java object arrays (not from primitive types) are more akin of lists, and
as.characterover lists does not dispatch any generic (not sure)...So the results would be:
and r's
toStringis equivalent to Object.toString.