如何在使用str时输出的开始处开始()

问题描述:

在R中使用str()函数从提供的输出的开始处开始而不是在函数运行后的结束处有任何方法吗?如何在使用str时输出的开始处开始()

基本上我想要一个更快的方式来到输出的开始,而不是滚动手动备份通过输出。这在查看像空间数据这样的大对象的结构时尤其有用。

+0

它对我来说很不清楚,你到底在问什么。你使用'str()'什么类型的对象?你想看什么类型的属性? [可重现的例子](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)将会有所帮助。 – MrFlick

+2

如果'str'的​​输出很长,那么有时候最好用'str(object,max.level = 2)'' – G5W

+0

http://stackoverflow.com/问题/ 3837520 /如何对防止最输出的-R到滚动客场中,庆典 – Dason

由Dason(https://stackoverflow.com/a/3837885/1017276)链接的答案的变体是将输出重定向到浏览器。

view_str <- function(x) 
{ 
    tmp <- tempfile(fileext = ".html") 
    x <- capture.output(str(x)) 

    write(paste0(x, collapse = "<br/>"), 
     file = tmp) 

    viewer <- getOption("viewer") 
    if (!is.null(viewer)) # If in RStudio, use RStudio's browser 
    { 
    viewer(tmp) 
    } 
    else{     # Otherwise use the system's default browser 
    utils::browseURL(tmp) 
    } 
} 

view_str(mtcars)