Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying R package data

Tags:

r

The bio.infer package contains a data frame /usr/lib/R/library/bio.infer/data/itis.ttable.rda that needs to be modified.

After loading the bio.infer package and attaching the data frame with the data() function, I wrote the data frame to a text file with write.table().

Using emacs I added another row to the data frame then applied read.table() to create a data frame, but it's in my pwd, not the R library data subdirectory for the bio.infer package.

What is the R function to copy/save/write either the text file or the local copy of itis.ttable to /usr/lib/R/library/bio.infer/data/itis.ttable.rda? I've looked in the R docs and my library of R books without seeing how to add this row to the library's data frame.

like image 584
Rich Shepard Avatar asked Sep 07 '25 09:09

Rich Shepard


1 Answers

Use load and save with rda files.

#Path to the data file
fname <- system.file("data", "itis.ttable.rda", package = "bio.infer")
stopifnot(file.exists(fname))

#Load data into new environment
e <- new.env()
load(fname, envir = e)

#Manipulate it
e$itis.ttable <- rev(e$itis.ttable) #or whatever

#Write back to file
save(itis.ttable, file = fname, envir = e)

Though as David Robinson mentioned, you probably shouldn't be overwriting the copy in the package. It is likely more sensible to make your own copy.

like image 153
Richie Cotton Avatar answered Sep 10 '25 16:09

Richie Cotton