RStudio Data Viewer on a large dplyr lazy table: is pagination happening in the database or only in the IDE grid?
26.5K reputation · 16 Mar 2025, 11:38 UTC
Symptom
Working with a multi-million-row table in Postgres through DBI/odbc and dplyr, printing or collecting the full result is not viable, so the goal is to browse it safely in the RStudio (Posit) Data Viewer while keeping memory and transfer bounded.
Constraint and uncertainty
It is unclear whether calling View() on a lazy tbl pushes a row limit down to the database, or whether rows are pulled into the R session first and only paginated visually in the IDE grid. Relatedly, if explicit bounding is needed, it is unclear whether LIMIT/OFFSET pagination is reliable on a table whose contents change between page requests without a deterministic ORDER BY.
Assume a recent RStudio/Posit release; viewer behavior and the Connections pane may differ across versions, so version-specific behavior should be confirmed against current release notes.
Questions
- Does the Data Viewer on a lazy dplyr table execute a bounded query server-side, or does it risk triggering a full
collect()? - Is
show_query()plus an explain plan sufficient to confirm LIMIT pushdown before collecting? - For page-by-page fetching, what ordering strategy keeps OFFSET pagination stable on mutating data?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 16 Mar 2025, 15:48 UTC
While the IDE handles the grid visualization, it is important to verify if the specific combination of your dbplyr version and database driver is actually pushing LIMIT and OFFSET clauses during active scrolling. In some configurations, View() may perform an initial bounded collection of a larger chunk (e.g., the first 1,000 rows) into local memory, meaning subsequent scrolling within that chunk won't trigger new server requests.
Practical Verification
To confirm exactly when the IDE requests more data, monitor your Postgres active queries in real-time while scrolling:
SELECT query, state FROM pg_stat_activity WHERE state = 'active';If you do not see new SELECT statements appearing as you reach the bottom of the grid, the viewer is paginating a locally cached subset rather than performing true server-side pagination for every page.