onErrorCell-methods: Behavior when error cells are detected

Description Usage Arguments Author(s) See Also Examples

Description

This function defines the behavior when reading data from a worksheet and error cells are detected.

Usage

1
2
## S4 method for signature 'workbook'
onErrorCell(object,behavior)

Arguments

object

The workbook to use

behavior

The behavior to follow when an error cell is detected. This is normally specified by a corresponding XLC error constant, i.e. either XLC$"ERROR.WARN" or XLC$"ERROR.STOP". XLC$"ERROR.WARN" means the error cell will be read as missing value (NA) and a corresponding warning will be generated (this is the default behavior). XLC$"ERROR.STOP" means that an exception will be thrown and further execution will be stopped immediately.

Author(s)

Martin Studer
Mirai Solutions GmbH http://www.mirai-solutions.com

See Also

workbook, readNamedRegion, readNamedRegionFromFile, readWorksheet,
readWorksheetFromFile

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# errorCell xlsx file from demoFiles subfolder of package XLConnect
demoExcelFile <- system.file("demoFiles/errorCell.xlsx", 
							  package = "XLConnect")

# Load workbook
wb <- loadWorkbook(demoExcelFile)

# Set error behavior to XLC$ERROR.WARN when detecting error cells
# Note: this is the default behavior
onErrorCell(wb, XLC$ERROR.WARN)
# Alternatively: wb$onErrorCell(XLC$ERROR.WARN)

# Read named region 'MyData' (with default header = TRUE)
data <- readNamedRegion(wb, name = "MyData")

# Now set error behavior to XLC$ERROR.STOP to immediately
# issue an exception and stop in case an error cell is
# detected
onErrorCell(wb, XLC$ERROR.STOP)
# Alternatively: wb$onErrorCell(XLC$ERROR.STOP)

# Read (again) named region 'MyData' (with default header = TRUE)
res <- try(readNamedRegion(wb, name = "MyData"))
# Did we get an error?
print(is(res, "try-error"))

XLConnect documentation built on April 6, 2018, 1:03 a.m.