Распечатать фрейм данных с длинными строковыми переменными - PullRequest
0 голосов
/ 23 сентября 2018

У меня есть фрейм данных, который содержит описания вопросов опроса, которые могут быть довольно длинными.Я пытаюсь найти способ аккуратно напечатать их.Вот пример:

foo <- data.frame(v1 = 1:5, 
                  v2 = rep(c("This is a really long description of a survey question that gives a bunch of information about the question and can be very long blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"), 5), 
                  v3 = 6:10)

Я бы хотел, чтобы напечатанный вывод выглядел примерно так:

  v1   v2                                       v3
1  1   This is a really long description of     6
       a survey question that gives a bunch 
       of information about the question and
       can be very long blah blah blah blah 
       blah blah blah blah blah blah blah 
       blah blah blah blah blah blah blah
2  2   This is a really long description of     7
       a survey question that gives a bunch 
       of information about the question and
       can be very long blah blah blah blah 
       blah blah blah blah blah blah blah 
       blah blah blah blah blah blah blah
3  3   This is a really long description of     8
       a survey question that gives a bunch 
       of information about the question and
       can be very long blah blah blah blah 
       blah blah blah blah blah blah blah 
       blah blah blah blah blah blah blah
4  4   This is a really long description of     9
       a survey question that gives a bunch 
       of information about the question and
       can be very long blah blah blah blah 
       blah blah blah blah blah blah blah 
       blah blah blah blah blah blah blah
5  5   This is a really long description of     10
       a survey question that gives a bunch 
       of information about the question and
       can be very long blah blah blah blah 
       blah blah blah blah blah blah blah 
       blah blah blah blah blah blah blah

Ответы [ 2 ]

0 голосов
/ 23 сентября 2018
flextable::flextable(foo, cwidth = c(0.5,7,0.5))

enter image description here

0 голосов
/ 23 сентября 2018

Вы можете использовать abbreviate() и DT::datatable().Таким образом, вы можете автоматически сокращать текст и видеть полный текст по клику:

library(DT)
texts <- paste0(1:5, "is is a really long description of a survey question that gives a bunch of information about the question and can be very long blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah")

foo <- data.frame(v1 = 1:5, 
                  v2 = paste0('<a href="#" onclick="alert(\'', texts, '\');">', 
                              abbreviate(texts, named = FALSE), '</a>'), 
                  v3 = 6:10)
datatable(foo, escape = FALSE)

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...