[R] Odp: Pausing script to allow user input from keyboard.

Petr PIKAL petr.pikal at precheza.cz
Fri Aug 6 16:04:22 CEST 2010


Hi

Some time ago somebody advised me to use

cat("\n","Enter filename","\n") # prompt
x=scan(n=1) # read 1 line from console

than use x in further code

Regards
Petr


r-help-bounces at r-project.org napsal dne 06.08.2010 15:52:17:

> 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.



More information about the R-help mailing list