existsName-methods: Checking existence of named ranges in a workbook

existsName-methodsR Documentation

Checking existence of named ranges in a workbook

Description

Checks the existence of a named range in a workbook.

Usage

## S4 method for signature 'workbook'
existsName(object, name, worksheetScope)

Arguments

object

The workbook to use

name

The name to check for

worksheetScope

Optional - the specific worksheet to check

Details

Returns TRUE if the specified name exists and FALSE otherwise. Note that the name argument is vectorized and therefore multiple names can be checked for existence in one method call.

If worksheetScope is provided, TRUE will be returned only if a matching named range exists in the local scope of the specified sheet. To explicitly match only in the global scope, pass "" as the value.

If option XLConnect.setCustomAttributes is TRUE (default FALSE), the worksheet scope in which the name is defined is set as attribute worksheetScope on the result.

Author(s)

Martin Studer
Mirai Solutions GmbH https://mirai-solutions.ch

See Also

workbook, createName, removeName, getDefinedNames, readNamedRegion,
writeNamedRegion

Examples

## Not run: 
# mtcars xlsx file from demoFiles subfolder of package XLConnect
mtcarsFile <- system.file("demoFiles/mtcars.xlsx", package = "XLConnect")

# Load workbook
wb <- loadWorkbook(mtcarsFile)

# Check if the name 'mtcars' exists
# (should return TRUE since the name is defined as 'mtcars!$A$1:$K$33')
existsName(wb, name = "mtcars")

# check if the worksheet-scoped name 'iris' exists
options(XLConnect.setCustomAttributes = TRUE)
wb <- loadWorkbook("demoFiles/iris.xlsx")

# should return TRUE with worksheet scope "iris"
res <- existsName(wb, name = "iris")
res
attributes(res)

## End(Not run)

XLConnect documentation built on Sept. 11, 2024, 8:04 p.m.