I'm laying out a Shiny app in which I want to allow users to up/download a restricted set of objects to an Rdata file.
Is there a standard way to validate it before loading the objects into the working environment?
If not, please consider the following:
loadValid<-function(file, envir = parent.frame(),objects=list(names=NA,pattern=".",validate=function() TRUE ), action="all" {
# names is a vector of the names of the desired objects (overrides pattern)
# pattern is a regex to match the names of the desired objects
# validate is a logical function to be applied to the objects, recycled to the length of names
# action= "all" - if all objects found and valid, "any","only" - no extraneous objects found
stageEnvir<-new.env()
load(file,envir=stageEnvir)
loadList<-ls(envir=stageEnvir)
proceed: if criteria met, assign desired objects to envir, return TRUE
else return FALSE
}
Is this a reasonable approach?
Alternatively,
save objects to file.Rdata
Rdata<-readBin(file.Rdata)
encrypt Rdata with private key
writeBin(Rdata, file.Rdata.crypt)
# give user public key to decrypt and use as he/she desires