Learn R Programming

XLConnect (version 0.1-5)

setMissingValue-methods: Setting a missing value string

Description

Sets the missing value string used when writing missing values to Excel.

Usage

## S3 method for class 'workbook,ANY':
setMissingValue(object,value)

Arguments

object
The workbook to use
value
The missing value string to use when writing data to Excel. If NULL, missing values result in blank cells (which is the default behavior). Any other values are coerced to character and used as missing value string.

Details

If no specific missing value string is set using setMissingValue then the default behavior is to map missing values to blank (empty) cells. The reason for this default mechanism is that the reverse operation of reading the data back into R results in the same original data types. However, if a missing value string is used (such as "NA"), then a numeric column for example with corresponding missing values would be read back in as a string (character) column. If you want to use e.g. numeric missing value identifiers such as e.g. -9999 then you should replace missing values first before you write them to Excel using XLConnect.

See Also

workbook, writeNamedRegion, writeWorksheet

Examples

Run this code
# Load workbook (create if not existing)
wb <- loadWorkbook("missingValue.xlsx", create = TRUE)

# Create a worksheet named 'airquality'
createSheet(wb, name = "airquality")

# Create a named region called 'airquality' on the sheet called
# 'airquality'
createName(wb, name = "airquality", formula = "airquality!$A$1")

# Set the missing value string to 'missing'
setMissingValue(wb, value = "missing")

# Write built-in data set 'airquality' to the above defined named region
writeNamedRegion(wb, airquality, name = "airquality")

# Save workbook
saveWorkbook(wb)

Run the code above in your browser using DataLab