# \donttest{
library(dplyr)
if (requireNamespace("DBI", quietly = TRUE) & requireNamespace("RSQLite", quietly = TRUE)) {
# connect DBMS
con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
# copy heartfailure to the DBMS with a table named TB_HEARTFAILURE
copy_to(con_sqlite, heartfailure, name = "TB_HEARTFAILURE", overwrite = TRUE)
# Using pipes ---------------------------------
# Visualization of all numerical variables
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
plot_normality()
# Positive values select variables, and In-memory mode and collect size is 200
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
plot_normality(platelets, sodium, collect_size = 200)
# Using pipes & dplyr -------------------------
# Plot 'sodium' variable by 'smoking' and 'death_event'
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
group_by(smoking, death_event) %>%
plot_normality(sodium)
# Plot using left and right arguments
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
group_by(smoking, death_event) %>%
plot_normality(sodium, left = "sqrt", right = "log")
# extract only those with 'smoking' variable level is "Yes",
# and plot 'sodium' by 'death_event'
con_sqlite %>%
tbl("TB_HEARTFAILURE") %>%
filter(smoking == "Yes") %>%
group_by(death_event) %>%
plot_normality(sodium)
# Disconnect DBMS
DBI::dbDisconnect(con_sqlite)
} else {
cat("If you want to use this feature, you need to install the 'DBI' and 'RSQLite' package.\n")
}
# }
Run the code above in your browser using DataLab