[R] Not display message when using system()

Marc Girondot marc_grt at yahoo.fr
Sun Aug 31 15:49:42 CEST 2014


Dear Henrik and list-members,

Thanks for your proposition but it is the same:

For example, no error message but no result:
 > pathfile <- system2(command="find", args="$HOME -type f -name 
'PuertoSanJose.csv'", stderr = FALSE, stdout="")
/Users/marc/Dropbox/DropBoxPerso/Data_Ale/Original/PuertoSanJose.csv
 > pathfile
[1] 1

Example 2 with error message but I get the result !
 > pathfile <- system2(command="find", args="$HOME -type f -name 
'PuertoSanJose.csv'", stderr = FALSE, stdout=TRUE)
Message d'avis :
l'exécution de la commande ''find' $HOME -type f -name 
'PuertoSanJose.csv' 2>/dev/null' renvoie un statut 1
 > pathfile
[1] "/Users/marc/Dropbox/DropBoxPerso/Data_Ale/Original/PuertoSanJose.csv"
attr(,"status")
[1] 1

I try another solution with options(warn=2) and try(xxx, silent=TRUE) to 
convert the warning in error and mask the error, but I cannot get the 
result anymore:
 > options(warn=2)
 > pathfile <- try(system2(command="find", args="$HOME -type f -name 
'PuertoSanJose.csv'", stderr = FALSE, stdout=TRUE), silent=TRUE)
 > pathfile
[1] "Error : (converti depuis l'avis) l'exécution de la commande ''find' 
$HOME -type f -name 'PuertoSanJose.csv' 2>/dev/null' renvoie un statut 1\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError: (converti depuis l'avis) l'exécution de la commande 
''find' $HOME -type f -name 'PuertoSanJose.csv' 2>/dev/null' renvoie un 
statut 1>

I try also this combinations but without success:
 > pathfile <- ""
 > try(assign("pathfile", system2(command="find", args="$HOME -type f 
-name 'PuertoSanJose.csv'", stderr = FALSE, stdout=TRUE), 
envir=globalenv()), silent=TRUE)
 > pathfile
[1] ""
 > try({pathfile <<- system2(command="find", args="$HOME -type f -name 
'PuertoSanJose.csv'", stderr = FALSE, stdout=TRUE)}, silent=TRUE)
 > pathfile
[1] ""

Sooo... any other idea ?

Thanks a lot

Marc

Le 29/08/2014 22:33, Henrik Bengtsson a écrit :
>
> As a start try to use system2() instead and look at its argument for 
> how to capture stdout and/or stderr. It's a neater function.
>
> It may be that those messages cannot be captured easily, but hopefully 
> they are.
>
> My $0.02
>
> Henrik
>
> On Aug 29, 2014 12:21 PM, "Marc Girondot" <marc_grt at yahoo.fr 
> <mailto:marc_grt at yahoo.fr>> wrote:
>
>     Dear list members,
>
>     My question concerns the use of system() in R version 3.1.1
>     patched and MacosX 10.9.4.
>     I want capture the result of a system command without displaying
>     error message. I give exemple.
>
>     In terminal, if I do this command:
>     find $HOME -type f -name 'PuertoSanJose.csv'
>
>     I get the correct answer but also a message about Permission
>     denied for one directory:
>     /Users/marc/Dropbox/DropBoxPerso/Data_Ale/Original/PuertoSanJose.csv
>     find: /Users/marc/Library/Saved Application
>     State/com.adobe.flashplayer.installmanager.savedState/data.data:
>     Permission denied
>
>     I want get the output of this command in R; then I do:
>     > pathfile <- system("find $HOME -type f -name
>     'PuertoSanJose.csv'", intern=TRUE, ignore.stderr = TRUE)
>     Message d'avis :
>     l'exécution de la commande 'find $HOME -type f -name
>     'PuertoSanJose.csv' 2>/dev/null' renvoie un statut 1
>
>     In pathfile, I have the correct answer but I have also a message
>     that I don't want.
>
>     My question is then: How to prevent display this message?
>
>     I try the following:
>     > pathfile <- capture.output(system("find $HOME -type f -name
>     'PuertoSanJose.csv'", intern=TRUE, ignore.stderr = TRUE))
>     Message d'avis :
>     l'exécution de la commande 'find $HOME -type f -name
>     'PuertoSanJose.csv' 2>/dev/null' renvoie un statut 1
>
>     The same
>
>     I try also:
>     > pathfile <- suppressMessages(system("find $HOME -type f -name
>     'PuertoSanJose.csv'", intern=TRUE, ignore.stderr = TRUE))
>     Message d'avis :
>     l'exécution de la commande 'find $HOME -type f -name
>     'PuertoSanJose.csv' 2>/dev/null' renvoie un statut 1
>
>     The same
>
>     The only solution to not see this message is:
>     > pathfile <- system("find $HOME -type f -name
>     'PuertoSanJose.csv'", intern=FALSE, ignore.stderr = TRUE)
>     /Users/marc/Dropbox/DropBoxPerso/Data_Ale/Original/PuertoSanJose.csv
>     > pathfile
>     [1] 1
>
>     But pathfile does not capture the output.
>
>     And the use of capture.output() does not help:
>     > pathfile <- capture.output(system("find $HOME -type f -name
>     'PuertoSanJose.csv'", intern=FALSE, ignore.stderr = TRUE))
>     /Users/marc/Dropbox/DropBoxPerso/Data_Ale/Original/PuertoSanJose.csv
>     > pathfile
>     character(0)
>
>
>     I really don't know how to not see this message...
>     If someone knows, I will appreciate !
>
>     Marc
>
>     ______________________________________________
>     R-help at r-project.org <mailto: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.
>


	[[alternative HTML version deleted]]



More information about the R-help mailing list