[R] Pausing script to allow user input from keyboard.
jim holtman
jholtman at gmail.com
Fri Aug 6 16:01:42 CEST 2010
Don't cut/paste; 'source' in the script. readLines is trying to read
from stdin which is where the commands are being read from. Using
'source' avoids that problem. You can also look at some examples I
have seen using tk/tcl where you can bring up a window for user input.
On Fri, Aug 6, 2010 at 9:52 AM, Johnny Tkach <johnny.tkach at utoronto.ca> wrote:
> Hi all,
>
> I have written a simple R script to help me analyze a large data set.
> I would like to have the script pause to allow the user to input a
> character string that is subsequently used as a filename when saving
> tables. I have tried to use the "readline" command - this seems to
> work fine when entering commands one by one, but when I copy and paste
> the entire script into R, it does not pause for input and just charges
> ahead writes the files. Any help is appreciated, I've copied and
> pasted the script below. Any help is appreciated - I am really new to
> R so if you can be as detailed as possible in your responses it would
> be greatly appreciated.
>
> Thanks,
>
> JT
>
> R version: R 2.11.1 GUI 1.34
> OS: OS 10.5.8
>
> Here's the script:
>
> #readfiles, "a" is nuclear measurements, "b" is cytoplasmic measurements
> a <- read.table(file.choose(), header=TRUE, sep=",")
> b <- read.table(file.choose(), header=TRUE, sep=",")
>
> #make a new data frame named "new" with important columns
> new <- data.frame(a$ImageNumber, a$AreaShape_Area, a
> $Intensity_IntegratedIntensity_OrigRFP, a
> $Intensity_IntegratedIntensity_OrigGFP, b
> $Intensity_MeanIntensity_OrigGFP)
>
> #make three new columns, "EstCytoIntensity" estimates Cytoplasmic
> intensity based on the mean measured intensity and an estimate of the
> nuclear volume to the cytoplasmic volume, "TotalIntensity" is the sum
> of the integrated nuclear intensity and estimated cytoplasmic
> intensity, "NucToCytoRatio" is the ratio of nuclear intensity divided
> by cytoplasmic intensity
> new$EstCytoIntensity <- b$Intensity_MeanIntensity_OrigGFP * (a
> $AreaShape_Area/0.3)
> new$TotalIntensity <- new$a.Intensity_IntegratedIntensity_OrigGFP + new
> $EstCytoIntensity
> new$NucToCytoRatio <- new$a.Intensity_IntegratedIntensity_OrigGFP / new
> $TotalIntensity
>
> #creates a table that determines the means for the measurements of all
> objects within an image
> library(plyr)
> newmean <- ddply(new, c("a.ImageNumber"), summarize,
> NuclearMean=mean(a.Intensity_IntegratedIntensity_OrigGFP, trim=0.01),
> CytoMean=mean(EstCytoIntensity, trim=0.01),
> IntensityMean=mean(TotalIntensity, trim=0.01),
> RatioMean=mean(NucToCytoRatio, trim=0.01))
>
> # input file name
> name <- readline(prompt="give filename ")
>
> #writes tables based on name given, both 'raw' containing all
> information and 'mean' containing the image means
>
> write.table(new, file=paste(name,"raw.csv", sep=""), row.names=FALSE,
> sep=",")
> write.table (newmean, file=paste(name, "mean.csv", sep=""),
> row.names=FALSE, sep=",")
>
> #end
>
>
>
>
>
> [[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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list