Search code examples
rreactable

row_count data not showing up in reactable


I have a dataframe with 6 variables (text excerpts and coder categories:Julie, Amy, Hannah, Mae).

library(sjmisc)
library( reactable)
myData <- data.frame(
    stringsAsFactors = FALSE,
    id = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L),
    Excerpt = c("Lorem ipus sed,",
                "Maecenas pharetra eleifend turpis, in volutpat enim malesuada quis. Dui",
                "Donec id magna dictum, dignissim mi eget, imperdiet nunc.",
                "Ut sed purus lorem. Aliquam sagittis ante odio, a fringilla urna luctus eu. Etiam ligu",
                "Integer eu erat faucibus, sodales ipsum quis, ultricies neque. In suscipit","Lorem ipshoncus sed,",
                "Maecenas pharetra eleifend turpis","Donec id magna dictum, dignissim",
                "Ut sed purus lorem. Aliquam",
                "Integer eu erat faucibus, sodales ipsum quis, ultricies neque. In suscipit"),
    Julie = c("I love pimento",
              "Eat more avocado","Eat more avocado","Fish are quiet pets",
              "I love pimento","I love pimento","I love pimento",
              "Eat more avocado","I love pimento","I love pimento"),
    Mae = c("I love pimento",NA,
            "I prefer cats","Fish are quiet pets","I love pimento",
            "I love pimento","Fish are quiet pets","Eat more avocado",
            "Doesn't belong","I love pimento"),
    Hannah = c("I love pimento",
               "dogs make the best pets","I prefer cats","I prefer cats",
               "I love pimento","I love pimento","I love pimento",
               "I prefer cats","I love pimento","I love pimento"),
    Amy = c("I love pimento",
            "Eat more avocado","Eat more avocado","Fish are quiet pets",
            "I love pimento","I love pimento","I love pimento",
            "Eat more avocado","I love pimento","I love pimento"))

I used the sjmisc package to count the number of times coders assigned a specific string to an excerpt

# counts strings across multiple columns
myData$fish <- row_count(myData, Julie:Amy, count = "Fish are quiet pets", append = FALSE)
myData$pimento <- row_count(myData, Julie:Amy, count = "I love pimento", append = FALSE)
myData$cats <- row_count(myData, Julie:Amy, count = "I prefer cats", append = FALSE)
myData$avocado <- row_count(myData, Julie:Amy, count = "Eat more avocado", append = FALSE)
myData$dogs <- row_count(myData, Julie:Amy, count = "dogs make the best pets", append = FALSE)
myData$notBelong <- row_count(myData, Julie:Amy, count =  "Doesn't belong", append = FALSE)

When I view myData I can see I now have a total of 12 variables and I can see the counts for each of the 6 new variables, however, when I try to use reactable to view the results, I can see the new columns I created, but no count data shows up in the columns.

reactable (myData)

What can I do to get the count data to show up in Reactable? Thank you.


Solution

  • You are struggling against the way the author of sjmisc::row_count intended the function to be used, therefore all the new columns are being named "row_count" which defeats reactable.

    Instead of your current use try (using just one example):

    myData <- row_count(myData, Julie:Amy, count = "Fish are quiet pets", var = "fish")
    

    then you'll have a column named fish and reactable will properly display it.

    Alternatively the author's intent was you do this...

    myData <- 
       myData %>% 
       row_count(Julie:Amy, 
                 count = "Fish are quiet pets", 
                 var = "fish", 
                 append = TRUE)