###########################################################################
# numerics, dates, missings, bool and string
example_file <- system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2")
wb1 <- wb_load(example_file)
# import workbook
wb_to_df(wb1)
# do not convert first row to column names
wb_to_df(wb1, col_names = FALSE)
# do not try to identify dates in the data
wb_to_df(wb1, detect_dates = FALSE)
# return the underlying Excel formula instead of their values
wb_to_df(wb1, show_formula = TRUE)
# read dimension without colNames
wb_to_df(wb1, dims = "A2:C5", col_names = FALSE)
# read selected cols
wb_to_df(wb1, cols = c("A:B", "G"))
# read selected rows
wb_to_df(wb1, rows = c(2, 4, 6))
# convert characters to numerics and date (logical too?)
wb_to_df(wb1, convert = FALSE)
# erase empty rows from dataset
wb_to_df(wb1, skip_empty_rows = TRUE)
# erase empty columns from dataset
wb_to_df(wb1, skip_empty_cols = TRUE)
# convert first row to rownames
wb_to_df(wb1, sheet = 2, dims = "C6:G9", row_names = TRUE)
# define type of the data.frame
wb_to_df(wb1, cols = c(2, 5), types = c("Var1" = 0, "Var3" = 1))
# start in row 5
wb_to_df(wb1, start_row = 5, col_names = FALSE)
# na string
wb_to_df(wb1, na.strings = "a")
###########################################################################
# Named regions
file_named_region <- system.file("extdata", "namedRegions3.xlsx", package = "openxlsx2")
wb2 <- wb_load(file_named_region)
# read dataset with named_region (returns global first)
wb_to_df(wb2, named_region = "MyRange", col_names = FALSE)
# read named_region from sheet
wb_to_df(wb2, named_region = "MyRange", sheet = 4, col_names = FALSE)
# read_xlsx() and wb_read()
example_file <- system.file("extdata", "openxlsx2_example.xlsx", package = "openxlsx2")
read_xlsx(file = example_file)
df1 <- wb_read(file = example_file, sheet = 1)
df2 <- wb_read(file = example_file, sheet = 1, rows = c(1, 3, 5), cols = 1:3)
Run the code above in your browser using DataLab