Skip to content

recordPlot usage: add snaps to a list.

1 message · Paul Johnson

#
I have trouble understanding the R list object and how to add objects
and get them out.  I'm trying to collect snapshots with recordPlot and
replay them.

Got great help from everybody here yesterday on my histogram function,
works fine to make the pictures:

histomatic <- function (s1,s2,s3,var){
  if (is.numeric (s2[[var]])) {     
  par(mfrow=c(3,1));
  rz <- range(s1[[var]], s2[[var]], s3[[var]]);
  breaks <- pretty(rz,40);
  hist(s1[[var]],breaks=breaks,xlab=var,main="Baseline");  
  hist(s2[[var]], breaks=breaks,xlab=var,main="Randomized Master
Schedule");
  hist(s3[[var]], breaks=breaks,xlab=var,main="Decentralized Dynamic
Schedule");
  a<-recordPlot();
}
}

Note I add in the a<-recordPlot() to try to keep a snapshot. That value
a gets returned.  I have tried in many many ways to add that snap a onto
a list of snaps, but all have failed, making me think list does not mean
what I think it does.  A

#intitialize a list
pictureList <- list();  
#loop through variable names, take return from each histomatic call, and
append
#to pictureList.
for (var in nameList)
  if (is.numeric (RandMastMod0[[var]])) {     
  pictureList <- c(pictureList,
histomatic(NoFlagMod0,RandMastMod0,NoMastMod0,var));
}

After that, pictureList is not a null thing,
$names
  [1] "displaylist" "gpar"        "displaylist" "gpar"       
"displaylist"
  [6] "gpar"        "displaylist" "gpar"        "displaylist" "gpar"
 [11] "displaylist" "gpar"        "displaylist" "gpar"       
"displaylist"

but i can't see how to access the snapshots from replayPlot().  Adding
the images into the list flattens them and makes the class of the items
no longer equal "recordedplot".
Error in if (class(x) != "recordedplot") stop("argument is not of class
\"recordedplot\"") :
        missing value where logical needed