This is what Rscript and R CMD BATCH are for.
Your problem is that you forgot to print the objects in your function:
auto-printing only occurs at the top level.
On Sun, 10 Aug 2008, Laura Poggio wrote:
> Dear all,
> I wrote a simple script in order to put together some functions and method
> to be executed on various files
> I am trying to have to possibility to call the script changing few
> parameters in order to use the different files.
> I succeeded partly using the function method.
> However in my script I call the sink() function in order to output the
> results to a .txt file. When using the function the file is empty, when
> running the script manually the file is fine. How can I solve that?
> Is there any other way to run a R script on different files with different
> names?
>
> Thank you very much in advance
>
> Laura
>
> ============================> EXAMPLE OF CODE
> ============================> km = function(a,o) {
>
> fld <- system.file("G:/ALRPC/JRC/IMG/",
package="rgdal")
> filename = as.name(paste (a, "-", o, sep=""))
> file <- read.table(paste("R_out/", filename, ".txt",
sep=""))
>
> obj <- kmenas(file, 5)
>
> sink(paste("R_out/res", filename, ".txt",
sep=""))
> "Kluster centers"
> obj$centers
> "Within size for clusters"
> obj$withinss
> "Cluster size"
> obj$size
> sink()
> }
>
> [[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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595