5

I have read these SO posts on getting rstudio to print out without truncating:

list output truncated - How to expand listed variables with str() in R

avoid string printed to console getting truncated (in RStudio)

The answers there involve making a adjustment to studio settings which would then cover all future outputs to the console.

Is there a ad hoc way to get r to print an entire string to the console?

I tried:

library(tidyverse)
library(foreach)

mystring <- foreach(i = 1:52) %do% {
  paste0("'_gaWeek",i,"'!A16:B;")
} %>% unlist %>% toString()

print(mystring, len = length(mystring))

> print(mystring, len = length(mystring))
[1] "'_gaWeek1'!A16:B;, '_gaWeek2'!A16:B;, '_gaWeek3'!A16:B;, '_gaWeek4'!A16:B;, '_gaWeek5'!A16:B;, '_gaWeek6'!A16:B;, '_gaWeek7'!A16:B;, '_gaWeek8'!A16:B;, '_gaWeek9'!A16:B;, '_gaWeek10'!A16:B;, '_gaWeek11'!A16:B;, '_gaWeek12'!A16:B;, '_gaWeek13'!A16:B;, '_gaWeek14'!A16:B;, '_gaWeek15'!A16:B;, '_gaWeek16'!A16:B;, '_gaWeek17'!A16:B;, '_gaWeek18'!A16:B;, '_gaWeek19'!A16:B;, '_gaWeek20'!A16:B;, '_gaWeek21'!A16:B;, '_gaWeek22'!A16:B;, '_gaWeek23'!A16:B;, '_gaWeek24'!A16:B;, '_gaWeek25'!A16:B;, '_gaWeek26'!A16:B;, '_gaWeek27'!A16:B;, '_gaWeek28'!A16:B;, '_gaWeek29'!A16:B;, '_gaWeek30'!A16:B;, '_gaWeek31'!A16:B;, '_gaWeek32'!A16:B;, '_gaWeek33'!A16:B;, '_gaWeek34'!A16:B;, '_gaWeek35'!A16:B;, '_gaWeek36'!A16:B;, '_gaWeek37'!A16:B;, '_gaWeek38'!A16:B;, '_gaWeek39'!A16:B;, '_gaWeek40'!A16:B;, '_gaWeek41'!A16:B;, '_gaWeek42'!A16:B;, '_gaWeek43'!A16:B;, '_gaWeek44'!A16:B;, '_gaWeek45'!A16:B;, '_gaWeek46'!A16:B;, '_gaWeek47'!A16:B;, '_gaWeek48'!A16:B;, '_gaWeek49'!A16:B;, '_gaWeek50'!A16:B;, '_ga... <truncated>

It's truncated. Is there an ad hoc way around this without changing rstudio settings? Such as by a function argument? I tried print() here.

Also, how do I get rid of the comma separator in between each instance above?

Doug Fir
  • 19,971
  • 47
  • 169
  • 299

1 Answers1

1

The short answer is "no" since, the option limiting the print is in the IDE itself, which you can't control from your program itself (I'm assuming you're not some crazy hacker here), and not a language feature. It's like trying to stop "WINDOWS" from doing things (although not).

Seems to me the easiest way (ad hoc) is to turn it on, do whatever, then turn it off. If you insist on not doing that, you need to write your own function:

myprint<- function(somestring,idelimit=100) {
    for(i in seq(1,nchar(somestring),idelimit+1)) {
         print(substr(somestring,i,i+idelimit));
    }
}

I'm not a fluent R coder so let me know if you catch a syntax error. The idea is simple - idelimit should be wherever studio truncates (I chose 100 arbitrarily), and basically you're doing the splitting yourself so string is printed line after line without truncation. Each time you take a portion at most idelimit long from somestring and print it.

kabanus
  • 24,623
  • 6
  • 41
  • 74
  • Thanks for answering. Having trouble getting your function to work, I don't think r recognises "idelimit"? – Doug Fir Aug 29 '17 at 10:19
  • Did you see it's supposed to be a function argument? I just gave it some default parameter - I don't know if 100 is right 4 u. I'm guessing you forgot to write it in the function signature. – kabanus Aug 29 '17 at 10:19
  • Sorry not following. This part here ```for(i in seq(0,nchar(somestring),idelimit))``` should it be numeric vector between 0:100? – Doug Fir Aug 29 '17 at 10:24
  • Suppose `somestring="Hello my name is Doug"`, and `idelimit=4`. If I counted correctly the amount of characters in `somestring` are 21, so it literally translates to `for i in 0 to 21 jumping by 4`, meaning `i` would equal 0 in the first iteration, 4 in the next, 8 in the next etc... Go over the R functions. – kabanus Aug 29 '17 at 10:28
  • @DougFir Sure enough I found a syntax error - a ")" in the print after `somestring` - should be ",". Also apparently R indexes from 1. – kabanus Aug 29 '17 at 10:45
  • Yeah it's not working but thanks all the same. Gonna adjust the GUI settings per your recommendation – Doug Fir Aug 29 '17 at 10:48
  • NP, but I just checked this final version in R-fiddle (copy paste this last version I just edited) - and it does. If you feel it's important to understand the programming concepts I would suggest one last look. – kabanus Aug 29 '17 at 10:50
  • OK, the comment above ```print(substr(somestring,i,i+idelimit));``` should be ```print(substr(somestring,i,i+idelimit,);```? I did try that and hit an error too. Can you share the rfiddle? – Doug Fir Aug 29 '17 at 11:10
  • Sorry I can't keep at this. Go here: http://www.r-fiddle.org/#/fiddle?id=7nVMA0C2&version=1 - that's a working example. – kabanus Aug 29 '17 at 11:12