This package contains a bunch of functions for data analysis tasks. It includes functions to write objects to an excel file using openxlsx, as well as creating a new directory based on a path.
You can install the latest version from Github:
devtools::install_github("kazeera/kazutils", upgrade_dependencies = FALSE)
Load package.
library(kazutils)
load_packages(c("dplyr", "openxlsx"))
out_dir <- create_folder("Folder/Subfolder")
The above line creates a directory called "Folder" if it doesn't already exist, and then a "Subfolder" directory within it if it doesn't already exist. Then it assigns "Folder/Subfolder" to the variable out_dir.
# Create a workbook
wb <- openxlsx::createWorkbook()
# Write a data frame to a worksheet
my_df <- DNase
write_df_to_Excel("Sheet1", my_df, wb)
# Write a list to a worksheet
my_list <- list(a=1:3, b=5:12)
write_list_to_Excel("Sheet2", my_list, wb)
# Save Excel file with .xlsx extension
filename <- sprintf("%s/file1.xlsx", out_dir) # gives "Folder/Subfolder/file1.xlsx"
openxlsx::saveWorkbook(wb, filename, overwrite = T)
fruits <- paste(rep(c("Green", "Yellow"), 5), rep(c("Apple", "Pear"), each=5), 1:10, sep="_")
print(fruits)
To get the 2nd part of each element, the fruit, do this:
get_nth_part(fruits, "_", 2)
To get the 1st part of each element, the color, do this:
get_nth_part(fruits, "_", 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.