clearNamedRegion-methods.Rd
Clears named regions in a workbook
.
# S4 method for class 'workbook,character'
clearNamedRegion(object, name, worksheetScope)
The workbook
to use
The name of the named region to clear
Optional - the name of the worksheet in which the region is scoped; useful if different sheets have scoped regions with the same name.
Clearing a named region/range means to clear all the cells associated with that named region. Clearing named regions can be useful if (named) data sets in a worksheet need to be replaced, i.e. data is first read, modified in R and finally written back to the the same named region. Without clearing the named region first, (parts of) the original data may still be visible if they occupied a larger range in the worksheet.
If worksheetScope
is unspecified, the first matching name found anywhere in the workbook
will be cleared. Otherwise, only a name specifically scoped to the worksheet may be cleared.
To only clear a name in global scope, pass ""
as the value.
if (FALSE) { # \dontrun{
# mtcars xlsx file from demoFiles subfolder of
# package XLConnect
demoExcelFile <- system.file("demoFiles/mtcars.xlsx",
package = "XLConnect")
# Load workbook
wb <- loadWorkbook(demoExcelFile)
# Read named region 'mtcars'
data <- readNamedRegion(wb, name = "mtcars", header = TRUE)
# Only consider cars with a weight >= 5
data <- data[data$wt >= 5, ]
# Clear original named region
clearNamedRegion(wb, name = "mtcars")
# Write subsetted data back
# Note: this is covering a smaller area now -
# writeNamedRegion automatically redefines the named region
# to the size/area of the data
writeNamedRegion(wb, data = data, name = "mtcars",
header = TRUE)
} # }