{"action":"opened","issue":{"url":"https://api.github.com/repos/tidyverse/tibble/issues/295","repository_url":"https://api.github.com/repos/tidyverse/tibble","labels_url":"https://api.github.com/repos/tidyverse/tibble/issues/295/labels{/name}","comments_url":"https://api.github.com/repos/tidyverse/tibble/issues/295/comments","events_url":"https://api.github.com/repos/tidyverse/tibble/issues/295/events","html_url":"https://github.com/tidyverse/tibble/issues/295","id":250651543,"number":295,"title":"Page to console (aka, \"| less\") for tbl_df ","user":{"login":"t-kalinowski","id":8462255,"avatar_url":"https://avatars1.githubusercontent.com/u/8462255?v=4","gravatar_id":"","url":"https://api.github.com/users/t-kalinowski","html_url":"https://github.com/t-kalinowski","followers_url":"https://api.github.com/users/t-kalinowski/followers","following_url":"https://api.github.com/users/t-kalinowski/following{/other_user}","gists_url":"https://api.github.com/users/t-kalinowski/gists{/gist_id}","starred_url":"https://api.github.com/users/t-kalinowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-kalinowski/subscriptions","organizations_url":"https://api.github.com/users/t-kalinowski/orgs","repos_url":"https://api.github.com/users/t-kalinowski/repos","events_url":"https://api.github.com/users/t-kalinowski/events{/privacy}","received_events_url":"https://api.github.com/users/t-kalinowski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-16T14:40:20Z","updated_at":"2017-08-16T14:40:20Z","closed_at":null,"body":"This might be a more pleasing and safer way to visually scan over a largish tibble at the console than just printing the whole table with `print.tbl_df(df, n = 1000)`. Here is an example implementation.\r\n\r\n```\r\npage <- function(df, rows_per_pg = 50L, force_base = FALSE) {\r\n\r\n  oopts <- options(tibble.print_max = rows_per_pg, max.print = 1000000)\r\n  on.exit(options(oopts))\r\n\r\n  if(force_base)\r\n    df <- as.data.frame(df)\r\n\r\n  n_pages <- nrow(df) %/% rows_per_pg\r\n\r\n  chunk <- tibble(\r\n    start =  1+(0:(n_pages-1)*rows_per_pg),\r\n    end = c(start[-n_pages]+rows_per_pg-1, nrow(df))\r\n  )\r\n\r\n  n_chunks <- nrow(chunk)\r\n\r\n  i <- 1\r\n\r\n  repeat {\r\n    idx <- seq.int(from = chunk$start[i], to = chunk$end[i])\r\n    cat(\"chunk\", i, \"of\", n_pages, \"-- \")\r\n    print(df[idx,])\r\n\r\n    if(i >= n_chunks) break\r\n\r\n    response <-\r\n      readline(\"Press enter to print next chunk, type a number to jump to a specific chunk, or input any other key + enter to exit: \")\r\n\r\n    if(!nzchar(response)) {\r\n      i <- i + 1\r\n      next\r\n    } else if (!is.na(response <- suppressWarnings(as.numeric(response)))) {\r\n      i <- min(c(n_chunks, response))\r\n      next\r\n    } else\r\n      break\r\n  }\r\n}\r\n```\r\n```\r\n> nycflights13::flights %>% page(5)\r\nchunk 1 of 67355 -- # A tibble: 5 x 19\r\n   year month   day dep_time sched_dep_time dep_delay arr_time\r\n  <int> <int> <int>    <int>          <int>     <dbl>    <int>\r\n1  2013     1     1      517            515         2      830\r\n2  2013     1     1      533            529         4      850\r\n3  2013     1     1      542            540         2      923\r\n4  2013     1     1      544            545        -1     1004\r\n5  2013     1     1      554            600        -6      812\r\n# ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,\r\n#   carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,\r\n#   air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,\r\n#   time_hour <dttm>\r\nPress enter to print next chunk, type a number to jump to a specific chunk, or input other key + enter to exit: \r\nchunk 2 of 67355 -- # A tibble: 5 x 19\r\n   year month   day dep_time sched_dep_time dep_delay arr_time\r\n  <int> <int> <int>    <int>          <int>     <dbl>    <int>\r\n1  2013     1     1      554            558        -4      740\r\n2  2013     1     1      555            600        -5      913\r\n3  2013     1     1      557            600        -3      709\r\n4  2013     1     1      557            600        -3      838\r\n5  2013     1     1      558            600        -2      753\r\n# ... with 12 more variables: sched_arr_time <int>, arr_delay <dbl>,\r\n#   carrier <chr>, flight <int>, tailnum <chr>, origin <chr>, dest <chr>,\r\n#   air_time <dbl>, distance <dbl>, hour <dbl>, minute <dbl>,\r\n#   time_hour <dttm>\r\nPress enter to print next chunk, type a number to jump to a specific chunk, or input other key + enter to exit: \r\n```\r\n\r\nIt still has a few rough edges. In particular, it would be nice if it \r\n* paged over columns as well (going left to right, top to bottom) and\r\n* preserved row numbers correctly in later chunks\r\n\r\nLet me know if there is interest and I would be happy to flesh this out a little and submit a PR."}}
{"actor":{"display_login":"t-kalinowski"}}