> x=split(1:1000,1:1000) > str(x)Although str() can suppress long output for vectors, but it can not suppress long output for list. I'm wondering how to suppress the output for long lists.
On Dec 3, 2009, at 10:11 PM, Peng Yu wrote:>> x=split(1:1000,1:1000) >> str(x) > > Although str() can suppress long output for vectors, but it can not > suppress long output for list. I'm wondering how to suppress the > output for long lists.Very simple ... You examine the code (for str.default it's not short, I will admit) and modify it to your specifications: str.default contains a section which is clearly for lists. These minor modifications to the list portion of the function will achieve what you request: Argument ... ,max.list=200 ) defined in the invocation segment: + for (i in seq_len(min(max.list,le) ) ){ ^^^^^^^^^^^^ + cat(indent.str, comp.str, nam.ob[i], ":", sep = "") + envir <- if (typeof(object[[i]]) == "promise") { + structure(object, nam = as.name(nam.ob[i])) + } ...and ... since it is a recursive data structure... + str(object[[i]], nest.lev = nest.lev + 1, indent.str = paste(indent.str, + ".."), nchar.max = nchar.max, max.level = max.level, + vec.len = vec.len, digits.d = digits.d, give.attr = give.attr, + give.head = give.head, give.length = give.length, + width = width, envir = envir, max.list) ^^^^^^^^ > x=split(1:10,1:10) > str(x) List of 10 $ 1 : int 1 $ 2 : int 2 $ 3 : int 3 $ 4 : int 4 $ 5 : int 5 $ 6 : int 6 $ 7 : int 7 $ 8 : int 8 $ 9 : int 9 $ 10: int 10 > x=split(1:10,1:10) > str(x, max.list=5) List of 10 $ 1 : int 1 $ 2 : int 2 $ 3 : int 3 $ 4 : int 4 $ 5 : int 5 -- David Winsemius, MD Heritage Laboratories West Hartford, CT
An alternative to str is the TkListView function in the TeachingDemos package. You still get the long listing, but it is in a separate window that you can control the scrolling on by hand. For more complicated lists/objects it provides a tree structure so that you can look at only the detailed parts that you are interested in. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Peng Yu > Sent: Thursday, December 03, 2009 8:11 PM > To: r-help at stat.math.ethz.ch > Subject: [R] shorten str() output for long list > > > x=split(1:1000,1:1000) > > str(x) > > Although str() can suppress long output for vectors, but it can not > suppress long output for list. I'm wondering how to suppress the > output for long lists. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Reasonably Related Threads
- Re shorten str() output for long list
- Inconsistent results between caret+kernlab versions
- Package Hmisc, functions summary.formula() and latex(), options pdig, pctdig, eps and prmsd
- utils::ls.str(): Partial argument name 'digits' to seq() (should be digits.d?)
- parsing pdf files