Rmarkdown table displays wrong number of columns

Hi,
When I display a table in Rmarkdown it is displaying with the wrong number of columns, compared with the number listed in the bottom-left of the table.
It says "1-8 of 11 columns" but it's only showing 7. When I scroll right, it says "9-11 of 11 columns", but it's actually showing columns 8 to 11.

The screenshot shows the first of these.

I'm running 2026.08.1 Build 195 on Windows 10 Pro.

Thanks
Louise

Can you give us the code you are using to get that output?

Please copy the code and paste it here between

```

```

This gives us formatted code that we can copy, paste, and run .
Thanks

Sure:

patients <- read.csv("datasets/hospital_doctors.csv")
patients[1:3,]

The file is the patients.csv file from the Hospital Management example on Kaggle (Hospital Management Dataset | Kaggle) or the doctors.csv file works similarly too.

This doesn't produce exactly the same set of columns I was looking at in that screenshot, but for me it still produces the same effect of one fewer column being shown than is reported.

Also, it's still showing the same behaviour today after restarting Rstudio (which for me always starts with a clear workspace)

Thanks.
I downloaded the data with no problem but I can not duplicate what you are getting. Of course I normally use Quarto rather RMarkdown so I may be missing something.

The first problem is that your output looks to be a tibble not a data.frame. The <chr> and dbl> indicate this.

There must be something happening in your code that I am not seeing because that table does not look like typical output from a tibble.

Here is what I get after I convert the data.frame to a tibble.

Are you producing a pdf_document or an html_document ?

Hi,
I restarted R and just ran the lines of code that I showed you, and got the same thing. The display is the inline table I get by running the R markdown code chunk interactively. I didn't knit the file.
I also didn't ask for a tibble, I simply asked R to show me the first few rows of the data frame.
Thanks
Louise

Aha got it. If I run the chunk I get your results. Everything is there, you just need to scroll using that tiny ‣ in the upper right of the table.

I almost never run chunks and have not used RMarkdown in 2–4 years so I missed this completely.

I still do not understand the tibble format.

I believe that RStudio is using rmarkdown::paged_table() to display the table. Apparently there is a "feature" (quirk? bug?) in that function in which it counts the row numbers as column 1, the first data column as column 2, etc. ... but reports the total number of columns in the original dataframe (not counting the row number). So if you scroll to the far right, you'll get "3 rows | n-12 of 11 columns" for some value of n.

Possibly the function was written by the same folks who do the federal budget?

Hi PRubin,
Thanks for the clarification! That does seem like a bug, but thanks for the explanation -- at least now I know why it's happening!

Ah, thanks That makes some kind of sense.

I don't know about the people who write your federal budget but ours are envious of the programmers' clarity.

1 Like