R Editor showing less rows

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
srk80
Posts: 18
Joined: Sat Mar 18, 2023 7:37 am

R Editor showing less rows

Post by srk80 »

I am trying to find the unique combinations of origin and dest in R editor. However, the output is not showing the rows number. This is the expected output.

# Find all unique origin and destination pairs
flights |>
distinct(origin, dest)
#> # A tibble: 224 × 2
#> origin dest
#> <chr> <chr>
#> 1 EWR IAH
#> 2 LGA IAH
#> 3 JFK MIA
#> 4 JFK BQN
#> 5 LGA ATL
#> 6 EWR ORD
#> # ℹ 218 more rows
Attachments
flights.csv
(4.34 KiB) Downloaded 18 times
Untitled.png
Untitled.png (89.13 KiB) Viewed 2109 times
User avatar
MAgojam
Posts: 458
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: R Editor showing less rows

Post by MAgojam »

Hey @srk80,

In jamovi's Rj Editor, when a script evaluates to a data.frame (or tibble), Rj automatically renders the output as an interactive jamovi table instead of raw console text.
This is why it displays formatted rows rather than the standard console header (# A tibble: 224 × 2, <chr>, etc.).

Depending on what output you need, here are the solutions:

If you want to force Rj to show the text printout (including row counts and data types) as seen in RStudio, convert data to a tibble and wrap the expression in print():

Code: Select all

library(dplyr)
# Print as a tibble to force R console text formatting
print(as_tibble(distinct(data, origin, dest)))
If you simply want to return the total number of unique origin-destination pairs:

Code: Select all

library(dplyr)
# Return the exact number of unique rows
data |> 
  distinct(origin, dest) |> 
  nrow()
If you want to see each unique combination along with how many times it appears:

Code: Select all

library(dplyr)
# Count occurrences per pair
data |> 
  count(origin, dest)
Cheers,
Maurizio
https://www.jamovi.org/about.html
srk80
Posts: 18
Joined: Sat Mar 18, 2023 7:37 am

Re: R Editor showing less rows

Post by srk80 »

As this functionality is an important one, can you integrate this option in jamovi instead of using R? It is really helpful and avoids the use of native R.
Post Reply