File: createNamedRegion.Rd

package info (click to toggle)
r-cran-openxlsx 4.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,128 kB
  • sloc: cpp: 1,722; ansic: 130; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wrappers.R
\name{createNamedRegion}
\alias{createNamedRegion}
\title{Create a named region.}
\usage{
createNamedRegion(wb, sheet, cols, rows, name)
}
\arguments{
\item{wb}{A workbook object}

\item{sheet}{A name or index of a worksheet}

\item{cols}{Numeric vector specifying columns to include in region}

\item{rows}{Numeric vector specifying rows to include in region}

\item{name}{Name for region. A character vector of length 1. Note region names musts be case-insensitive unique.}
}
\description{
Create a named region
}
\details{
Region is given by: min(cols):max(cols) X min(rows):max(rows)
}
\examples{
## create named regions
wb <- createWorkbook()
addWorksheet(wb, "Sheet 1")

## specify region
writeData(wb, sheet = 1, x = iris, startCol = 1, startRow = 1)
createNamedRegion(
  wb = wb,
  sheet = 1,
  name = "iris",
  rows = 1:(nrow(iris) + 1),
  cols = 1:ncol(iris)
)


## using writeData 'name' argument
writeData(wb, sheet = 1, x = iris, name = "iris2", startCol = 10)

out_file <- tempfile(fileext = ".xlsx")
\dontrun{
saveWorkbook(wb, out_file, overwrite = TRUE)

## see named regions
getNamedRegions(wb) ## From Workbook object
getNamedRegions(out_file) ## From xlsx file

## read named regions
df <- read.xlsx(wb, namedRegion = "iris")
head(df)

df <- read.xlsx(out_file, namedRegion = "iris2")
head(df)
}
}
\seealso{
\code{\link{getNamedRegions}}
}
\author{
Alexander Walker
}