As part of a larger function I have code similar to the reduced example below. The user is instructed to choose a file, which gets read using read.csv. In this example, I just have the name of the file print out. When I call this function with choosefile(), the file dialog box appears before the first cat line is printed. After I choose a file, both cat lines are printed. choosefile <- function (){ cat("Choose the data file.\n") filename <- file.choose(new = FALSE) cat("You chose: ", filename, sep = "") } Is there a way to force the first cat line to print before the call to file.choose? I'm using R 2.4.0 Patched (2006-11-24 r39989) on OS X. Session info below. Any suggestions would be greatly appreciated. Kevin Middleton ------- > sessionInfo() R version 2.4.0 Patched (2006-11-24 r39989) powerpc-apple-darwin8.8.0 locale: en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods" "base"
turn off the buffered write or use flush.console(). On 11/25/06, Kevin Middleton <kmm at mid-town.org> wrote:> As part of a larger function I have code similar to the reduced > example below. The user is instructed to choose a file, which gets > read using read.csv. In this example, I just have the name of the > file print out. > > When I call this function with choosefile(), the file dialog box > appears before the first cat line is printed. After I choose a file, > both cat lines are printed. > > choosefile <- function (){ > cat("Choose the data file.\n") > filename <- file.choose(new = FALSE) > cat("You chose: ", filename, sep = "") > } > > Is there a way to force the first cat line to print before the call > to file.choose? I'm using R 2.4.0 Patched (2006-11-24 r39989) on OS > X. Session info below. > > Any suggestions would be greatly appreciated. > > Kevin Middleton > > ------- > > > sessionInfo() > R version 2.4.0 Patched (2006-11-24 r39989) > powerpc-apple-darwin8.8.0 > > locale: > en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" > "methods" "base" > > ______________________________________________ > R-help at stat.math.ethz.ch 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 you are trying to solve?
I believe this is specific to the MacOS (and Windows) GUI, which you did not mention you were using. See ?flush.console for the solution. Your subject line is misleading: it is the console that is delaying showing the result. On Sat, 25 Nov 2006, Kevin Middleton wrote:> As part of a larger function I have code similar to the reduced > example below. The user is instructed to choose a file, which gets > read using read.csv. In this example, I just have the name of the > file print out. > > When I call this function with choosefile(), the file dialog box > appears before the first cat line is printed. After I choose a file, > both cat lines are printed. > > choosefile <- function (){ > cat("Choose the data file.\n") > filename <- file.choose(new = FALSE) > cat("You chose: ", filename, sep = "") > } > > Is there a way to force the first cat line to print before the call > to file.choose? I'm using R 2.4.0 Patched (2006-11-24 r39989) on OS > X. Session info below. > > Any suggestions would be greatly appreciated. > > Kevin Middleton > > ------- > > > sessionInfo() > R version 2.4.0 Patched (2006-11-24 r39989) > powerpc-apple-darwin8.8.0 > > locale: > en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] "stats" "graphics" "grDevices" "utils" "datasets" > "methods" "base"-- 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