setnames: Modify column names for ffdf, cohort or data.table objects

Description Usage Arguments Details Value Examples

View source: R/setnames.R

Description

A version of the setnames data.table function for ffdf data frames or cohort objects.

Usage

1
2
3
4
5
6
7
setnames(x, old, new)
## S3 method for class 'data.table'
setnames(x, old, new)
## S3 method for class 'cohort'
setnames(x, old, new)
## S3 method for class 'ffdf'
setnames(x, old, new)

Arguments

x

A data.table, cohort or ffdf object

old

Old column names or positions, or a vector of all new column names if new is missing.

new

New column names

Details

Defines 'setnames' as a generic function. For data.table objects, it dispatches the setnames method in the data.table package. For cohort objects, it also updates the description table and idcolname. For FFDF objects, the object is not modified by reference but the modified object is returned.

Value

Invisibly returns the modified object. If it is a data.table, it is also updated by reference.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
COHORT <- cohort(data.table(anonpatid = 1:3, indexdate = as.IDate(c("2012-1-3", 
	"2012-1-2", "2010-1-9"))))
FFDFCOHORT <- as.ffdf(COHORT)

# Data table cohort does not need assignment for changing names
print(COHORT)
setnames(COHORT, c('anonpatid', 'indexdate'), c('id', 'startdate'))
print(COHORT)

print(FFDFCOHORT)
FFDFCOHORT <- setnames(FFDFCOHORT, c('anonpatid', 'indexdate'), c('id', 'startdate'))
print(FFDFCOHORT)

CALIBERdatamanage documentation built on Nov. 23, 2021, 3 p.m.