rda {gnn}R Documentation

Check Existence, Read, Save and Rename .rda Files and their Objects

Description

Check Existence, Read, Save and Rename .rda Files and their Objects.

Usage

exists_rda(file, names, package = NULL)
read_rda(file, names, package = NULL)
save_rda(..., file, names = NULL)
rename_rda(oldname, oldfile = paste0(oldname, collapse = "_"),
           newname, newfile = paste0(newname, collapse = "_", ".rda"),
	   package = NULL)

Arguments

file
exists_rda()

character string (with or without ending .rda) specifying the name of the file to check existence of (if pacakge = NULL) or in (otherwise).

read_rda()

character string (with or without ending .rda) specifying the file to read from.

save_rda()

character string (with or without ending .rda) specifying the file to save to.

names
exists_rda()

character vector of names of objects to be checked for existence.

read_rda()

character vector of names of objects to be read. If not provided, a name is constructed from file.

save_rda()

character vector of names under which the objects in ... are saved in file. If NULL, the names of the objects provided by ... are taken as default values.

package
exists_rda()

package name in which to check or NULL (the default) in which case the current working directory is checked.

read_rda(), rename_rda()

package name from which to load the objects or NULL (the default) in which case the current working directory is searched.

...

any number of R objects.

oldname

character string specifying the object to be read.

oldfile

file name (with or without ending .rda) specifying from which the object named oldname is read.

newname

character string specifying the new name under which the object is to be saved.

newfile

file name (with ending .rda) specifying where the object named oldname is saved under the name newname.

Value

exists_rda()

logical indicating whether the .rda file file exists (if names is not provided) or whether the objects with names names exist inside file (if names is provided).

read_rda()

the object read from the .rda.

save_rda()

nothing (generated an .rda by side-effect).

rename_rda()

nothing (generated an .rda by side-effect).

Author(s)

Marius Hofert

See Also

See the underlying functions load(), data() and save() (among others).

Examples

 # to avoid win-builder error "Error: Installation of TensorFlow not found"
## Create dummy objects and save them in a temporary file
myobj1 <- 1:10
myobj2 <- 10:1
file1. <- tempfile("foo1", fileext = ".rda") # tempfile() for CRAN checks
file1 <- rm_ext(file1.)
save(myobj1, myobj2, file = file1.)
rm(myobj1, myobj2)

## Testing exists_rda()
## Check the existence of file 'file' with file ending '.rda'
stopifnot(exists_rda(file1.))
## Check the existence of file 'file' without file ending '.rda'
stopifnot(exists_rda(file1))
## Check the existence of 'myobj1' inside 'file' with file ending '.rda'
stopifnot(exists_rda(file1., names = "myobj1"))
## Check the existence of 'myobj1' inside 'file' without file ending '.rda'
stopifnot(exists_rda(file1,  names = "myobj1"))
## Check the existence of a file named 'SP500_const' in 'qrmdata'
stopifnot(exists_rda("SP500_const", package = "qrmdata"))
## Check the existence of 'SP500_const_info' inside 'SP500_const' in 'qrmdata'
stopifnot(exists_rda("SP500_const", names = "SP500_const_info", package = "qrmdata"))

## Testing read_rda()
stopifnot(names(read_rda(c("myobj1", "myobj2"), file = file1.)) == c("myobj1", "myobj2"))
foo <- read_rda("SP500_const", names = "SP500_const_info", package = "qrmdata")
stopifnot(is.data.frame(foo))

## Testing save_rda()
file2. <- tempfile("foo2", fileext = ".rda") # for CRAN
save_rda(foo, file = file2., names = "SP500info2")
bar <- read_rda(file2., names = "SP500info2")
stopifnot(identical(bar, foo))

## Clean-up
stopifnot(file.remove(file1., file2.))


[Package gnn version 0.0-3 Index]