The viewData package is an alternative to the
View(...) function. It's a thin wrapper around the DT library.
The motivation to build this package was
In my data cleaning and transformation workflow, I like to do spot checks of the data to make sure I understand what the code/functions are doing and to see if there are any potential issues with the underlying data or methods.
The base function
View() is nice, but I wanted to incorporate the features in
DT (e.g., search, filter, view rows, clickable links, etc.). I also wanted to be able to view the data in a browser window (as opposed to Rstudio) which could then be moved to a second monitor. This would allow me to interact with the data and make adjustments to the code without having to resize the Rstudio panes in order to see the data and code on one line.
Since I built the package, I've found the renderULS argument to be very useful if I'm unfamiliar with dataset and I wanted to know more about a category. This works beautifully in a tidywork flow (see examples below).
viewData package can be installed using the
The only function
viewData(...) is a simple wrapper around the DT package and takes the following options (shown below are the default options).
viewData(data, showFilter = FALSE, row.names = FALSE, renderURLS = FALSE, launch.browser = FALSE)
data: name of the data object you want to view (e.g., mtcars, iris, etc.)
TRUE, table filters will be displayed. The default option is
row.names: By default,
row.namesare not printed. Use
row.names = TRUEto print row names
renderURLS: If your data contains url, use
renderURLS = TRUEto make them clickable. These links must be prepared beforehand and wrapped in
TRUE, the table will be display in your system's default browser.
Access keys are also enabled for interacting with table outputs. The current shortcut is for moving the cursor into the search field. This shortcut is:
The combination of keys to enable this functionality varies by browser and OS. See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey for more information.
library(viewData) viewData(data= iris)
Alternatively, you can use
viewData(data = iris, showFilter = TRUE)
viewData(data = mtcars, showFilter = TRUE, row.names = TRUE)
View data in browser
viewData(data= iris, launch.browser = TRUE)
Make clickable URLS
# assign to tmp object df <- iris # paste urls df$urls <- paste0('<a href="https://www.google.com.au/search?q=',df$Species,'">',df$Species,'</a>') # view viewData(data= df, renderURLS = TRUE)
Make clickable URLS the tidy way
iris %>% mutate(Species = paste0('<a href="https://www.google.com/search?q=',Species,'" target="_blank" rel="noopener">',Species,'</a>')) %>% select(Species, everything()) %>% viewData::viewData(data = ., showFilter = TRUE, renderURLS = TRUE, launch.browser = TRUE)
The viewData package relies on the following packages
DT. If you run into any errors during the installation or usage, it might be due to missing packages or they are outdated. Run the following lines to install/update these packages, and then reinstall the
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.