Re: [R] shorten str() output for long list

2009-12-04 Thread Martin Maechler

 DW == David Winsemius dwinsem...@comcast.net
 on Fri, 4 Dec 2009 01:18:56 -0500 writes:

DW 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.

DW Very simple ... You examine the code (for str.default it's not short,  
DW I will admit) and modify it to your specifications:

DW str.default contains a section which is clearly for lists. These minor  
DW modifications to the list portion of the function will achieve what  
DW you request:

DW Argument ... ,max.list=200 )   defined in the invocation segment:

DW + for (i in seq_len(min(max.list,le) ) ){
DW 
DW +   cat(indent.str, comp.str, nam.ob[i], :, sep = )
DW +   envir - if (typeof(object[[i]]) == promise) {
DW + structure(object, nam = as.name(nam.ob[i]))
DW +   }

DW ...and ... since it is a recursive data structure...

DW +   str(object[[i]], nest.lev = nest.lev + 1,  
DW indent.str = paste(indent.str,
DW + ..), nchar.max = nchar.max, max.level =  
DW max.level,
DW + vec.len = vec.len, digits.d = digits.d,  
DW give.attr = give.attr,
DW + give.head = give.head, give.length = give.length,
DW + width = width, envir = envir, max.list)
DW 

(defensive programming requires to use  'max.list=max.list' in the line above.)

David, I know you as a smart R user.
If you provide patches against the *sources* , i.e.
  https://svn.r-project.org/R/trunk/src/library/utils/R/str.R
*and* the help file man/str.Rd

I'll incorporate these into str() ,
not anymore for R 2.10.1 though.

With regards,
Martin Maechler, ETH Zurich

 x=split(1:10,1:10)
 str(x)
DW List of 10
DW $ 1 : int 1
DW $ 2 : int 2
DW $ 3 : int 3
DW $ 4 : int 4
DW $ 5 : int 5
DW $ 6 : int 6
DW $ 7 : int 7
DW $ 8 : int 8
DW $ 9 : int 9
DW $ 10: int 10
 x=split(1:10,1:10)
 str(x, max.list=5)
DW List of 10
DW $ 1 : int 1
DW $ 2 : int 2
DW $ 3 : int 3
DW $ 4 : int 4
DW $ 5 : int 5

DW -- 
DW David Winsemius, MD
DW Heritage Laboratories
DW West Hartford, CT

DW __
DW R-help@r-project.org mailing list
DW https://stat.ethz.ch/mailman/listinfo/r-help
DW PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
DW and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


Re: [R] shorten str() output for long list

2009-12-04 Thread Greg Snow
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.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Peng Yu
 Sent: Thursday, December 03, 2009 8:11 PM
 To: r-h...@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@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.

__
R-help@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.


Re: [R] shorten str() output for long list

2009-12-03 Thread David Winsemius


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

__
R-help@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.


Re: [R] shorten str() output for long list

2009-12-03 Thread Peng Yu
On Fri, Dec 4, 2009 at 12:18 AM, David Winsemius dwinsem...@comcast.net wrote:

 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

This might be useful to others. Could you add this to the future release of R?

__
R-help@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.


Re: [R] shorten str() output for long list

2009-12-03 Thread Henrik Bengtsson
str(head(x))

str(head(x, n=5))

/H

On Thu, Dec 3, 2009 at 10:18 PM, David Winsemius dwinsem...@comcast.net wrote:

 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

 __
 R-help@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.


__
R-help@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.