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

htmlTable-1.3 shows factors as integers instead of characters #4

Closed
zeehio opened this Issue May 20, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@zeehio
Copy link
Contributor

zeehio commented May 20, 2015

Thanks for this package. I was just trying it with a data frame and I found an issue:

    library(htmlTable)
    data(iris)
    head(iris)
    htmlTable(iris)

image

The generated table shows the Species column as an integer column. I expected it to be shown as a character.

As a workaround I can convert the factor to character

    iris_char <- iris
    iris_char$Species <- as.character(iris_char$Species)
    htmlTable(iris_char)

image

But it would be nice if htmlTable did that for me. Is it feasible to implement this?

@zeehio

This comment has been minimized.

Copy link
Contributor Author

zeehio commented May 20, 2015

I don't know much about wrappers and methods. This seems to solve my issue:

library(htmlTable)
data(iris)

htmlTable.data.frame <- function(x, ...) {
  # Convert all factors to characters to print them as they expected
  i <- sapply(x, is.factor)
  x[i] <- lapply(x[i], as.character)

  htmlTable:::htmlTable.default(x,...)
}

htmlTable(iris)

image

@gforge

This comment has been minimized.

Copy link
Owner

gforge commented May 20, 2015

I haven't thought about the factors - good suggestion, I'll try to add this. /M

@gforge

This comment has been minimized.

Copy link
Owner

gforge commented May 20, 2015

Fix added to develop version

@gforge gforge closed this May 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment