Hello, I have a loop where I iterate performance data files within a folder, parse and plot them in one shot (see below). However, when executing plot_raw which invokes dev.new(..) all windows come out blank whereas if I execute each file outside of a loop then I can see the plots properly. What's wrong here? Thanks in advance, Best regards, Giovanni # given a directory name, it will iterate all files that match the given pattern #basedir <- "/Users/bravegag/code/asl11/data/2k-r1-test-20111111_data/" basedir <- "/Users/bravegag/code/asl11/data/nclients_2_128-20111110_data/" pattern <- paste("logs.*cl\\-.*mw\\-.*db\\-.*\\-client\\.dat",sep="") all_files <- dir(path=basedir, pattern=pattern) throughput <- NULL response <- NULL #file_name <- all_files[1] # iterate all files for (file_name in all_files) { print(paste("processing", file_name, "...")) df <- read.table(paste(basedir, file_name, sep="")) # read the data as a data frame names(df)[names(df)=="V1"] <- "Time" names(df)[names(df)=="V2"] <- "Partitioning" names(df)[names(df)=="V3"] <- "Workload" names(df)[names(df)=="V4"] <- "Runtime" # get rid of first and last n minutes df <- subset(df, df$Time > warmup_cooldown_minutes) df <- subset(df, df$Time < (max(df$Time) - warmup_cooldown_minutes)) # ======================================================================================== # Throughput # ======================================================================================== if (decouple) { dft <- aggregate(x=df$Runtime, by=list(df$Time,df$Workload), FUN=length) names(dft)[names(dft)=="Group.1"] <- "Time" names(dft)[names(dft)=="Group.2"] <- "Workload" names(dft)[names(dft)=="x"] <- "Y" } else { dft <- aggregate(x=df$Runtime, by=list(df$Time), FUN=length) names(dft)[names(dft)=="Group.1"] <- "Time" names(dft)[names(dft)=="x"] <- "Y" } dft$se <- 0 plot_raw(dft,connect=TRUE,label=file_name) } [[alternative HTML version deleted]]
On Nov 12, 2011, at 6:04 PM, Giovanni Azua wrote:> Hello, > > I have a loop where I iterate performance data files within a > folder, parse and plot them in one shot (see below). > > However, when executing plot_raw which invokes dev.new(..) all > windows come out blank whereas if I execute each file outside of a > loop then I can see the plots properly.Perhaps ...(you did not say what package this plot_raw function comes from) ... Read the FAQ about why lattice plot don't print. (It applies to all grid based plotting functions.) -- David> What's wrong here? > > Thanks in advance, > Best regards, > Giovanni > > # given a directory name, it will iterate all files that match the > given pattern > #basedir <- "/Users/bravegag/code/asl11/data/2k-r1- > test-20111111_data/" > basedir <- "/Users/bravegag/code/asl11/data/ > nclients_2_128-20111110_data/" > pattern <- paste("logs.*cl\\-.*mw\\-.*db\\-.*\\-client\\.dat",sep="") > all_files <- dir(path=basedir, pattern=pattern) > > throughput <- NULL > response <- NULL > > #file_name <- all_files[1] > > # iterate all files > for (file_name in all_files) { > print(paste("processing", file_name, "...")) > > df <- read.table(paste(basedir, file_name, sep="")) # > read the data as a data frame > names(df)[names(df)=="V1"] <- "Time" > names(df)[names(df)=="V2"] <- "Partitioning" > names(df)[names(df)=="V3"] <- "Workload" > names(df)[names(df)=="V4"] <- "Runtime" > > # get rid of first and last n minutes > df <- subset(df, df$Time > warmup_cooldown_minutes) > df <- subset(df, df$Time < (max(df$Time) - warmup_cooldown_minutes)) > > # > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > =====================================================================> # Throughput > # > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > =====================================================================> if (decouple) { > dft <- aggregate(x=df$Runtime, by=list(df$Time,df$Workload), > FUN=length) > names(dft)[names(dft)=="Group.1"] <- "Time" > names(dft)[names(dft)=="Group.2"] <- "Workload" > names(dft)[names(dft)=="x"] <- "Y" > > } else { > dft <- aggregate(x=df$Runtime, by=list(df$Time), FUN=length) > names(dft)[names(dft)=="Group.1"] <- "Time" > names(dft)[names(dft)=="x"] <- "Y" > } > dft$se <- 0 > plot_raw(dft,connect=TRUE,label=file_name) > } > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
On Nov 13, 2011, at 3:23 PM, David Winsemius wrote:>>> Please read both my comments and the FAQ more carefully . You are inadequately considering the information that has been offered to you. >>> >> Ok you wanted to make sure I have to read the FAQ well I didn't have to :) Googling using your suggestion found relevant matches and now it works. > > Where does this resistance to reading the FAQ come from?It is not resistance, the FAQ is very helpful for basic general questions but it can not cover all details. Sometimes it is very hard to find a specific detailed answer within a general FAQ. I have read the FAQ, what makes you think I didn't before? I just could not find the information I was looking for.>> I had to wrap the ggplot call within a "print" for my loop to work which is IMHO one of the most obfuscated use-cases for using print I have bumped into. > > It is a case of isolating the functional aspects of the plot-construction process from the side-effects of interacting with a graphics device. > >> So every user-defined function that try to plot anything has to be wrapped inside a print just in case it ever gets called from within a loop > > That is not how I understand it. One reason is so there is an object in the workspace that can be later modified. And I suspect the authors (and I am not one of them) imagined that there may be multiple steps in creation of the object, not all of which should result in a plot appearing if this is being done programatically. This is especially appropriate (it would seem to me) for the ggplot plotting model, which adds a variety of layers to a core object. It is also imagined that you may be sending this object to one of a variety of devices. >Ok bottom line is always wrap the plot call whatever it is within a print for the just in case. Cheers, Giovanni