Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscript out of bounds error from tbl data frame above 20 rows #4

Open
samgilbert1983 opened this issue Oct 3, 2017 · 4 comments
Open

Comments

@samgilbert1983
Copy link

samgilbert1983 commented Oct 3, 2017

I'm getting a subscript out of bounds error when I try to insert a data frame tbl with more than 20 rows into an html document.

require(R2HTML)
require(dplyr)

df <-
  tbl_df(data.frame(col1 = 1:21))

working_dir <- paste0("/home/", system('whoami', intern = TRUE))

HTML_file <- HTMLInitFile(outdir = working_dir,
                          filename = "file")

HTML(df)

The above example errors with:

Error in x.formatted[i, ] : subscript out of bounds

Removing the tbl_df() works as expected.

Session info:

R version 3.3.3 RC (2017-02-27 r72279)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

dplyr_0.5.0  R2HTML_2.3.2

tibble_1.3.3
@nalimilan
Copy link
Owner

Sorry, but nobody actively develops the package nowadays. If you want this to be fixed I'm afraid you'll have to debug it yourself. There's probably something that tibble does differently from data frames, despite pretending to be a data frame.

@tfry-git
Copy link
Collaborator

For what it's worth, the cause of the error is:

dim(df)  # [1] 21  1
as.matrix(format(df)) # [1] 14  1

HTML.data.frame - reasonably, IMO - assumes that both are equal, but tibble:::format.tbl_df() shortens it beyond 20 rows (and formats it is a way that does not immediately make any sense to me).

HTML(data.frame(df)) works.

@tfry-git
Copy link
Collaborator

Explicitly coercing x <- data.frame(x) inside HTML.data.frame() would do the trick in this case, but I'm not entirely sure, whether there could be unintended side-effects for other data.frame derived classes.

@aitap
Copy link
Contributor

aitap commented Nov 7, 2022

Thanks for the diagnosis!

One way of solving this which sounds relatively safe would be to define a separate method for tibbles:

HTML.tbl_df <- function(x, ...) HTML(data.frame(x), ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants