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

WISH: Customizable print method for character vector with long text #163

Open
chainsawriot opened this issue May 17, 2024 · 0 comments
Open

Comments

@chainsawriot
Copy link

chainsawriot commented May 17, 2024

The print method of character vector has been a major issue when text analysts deal with large text datasets.

To illustrate the issue:

gibberish <- paste0(sample(c(LETTERS, letters, " "), 100000, replace = TRUE), collapse = "")
rep(gibberish, 10000)

The printing of the vector with very long texts blocks the R interpreter 1. As far as I know, there is no way to override the default printing method of character vector.

Of course, the community comes up with different solutions, e.g.

gibberish <- paste0(sample(c(LETTERS, letters, " "), 100000, replace = TRUE), collapse = "")
tibble::tibble(rep(gibberish, 10000))
gibberish <- paste0(sample(c(LETTERS, letters, " "), 100000, replace = TRUE), collapse = "")
quanteda::corpus(rep(gibberish, 10000))

However, it would be good if there is a way to customize the print method of character vector, so that it can truncate the printing of very long texts.

Footnotes

  1. In this case, it will print ultimately because the length of the vector is not that long. But for real life datasets, it blocks the interpreter so that one has to kill it. print(max = 10) works to cut the number of items to be printed, but not the length of the text itself. object.size(gibberish) in this case is just 98KB, real life text data can easily be a few MB per item.

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

1 participant