clearNamedRegion-methods: Clearing named regions in a workbook

clearNamedRegion-methodsR Documentation

Clearing named regions in a workbook


Clears named regions in a workbook.


  ## S4 method for signature 'workbook,character'
clearNamedRegion(object, name)



The workbook to use


The name of the named region to clear


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.


Nicola Lambiase
Mirai Solutions GmbH

See Also

workbook, clearSheet, clearRange, clearRangeFromReference, clearSheet


  ## Not run: 
# 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) 

## End(Not run) 

XLConnect documentation built on Oct. 21, 2022, 9:05 a.m.