[R] Not display message when using system()

Marc Girondot marc_grt at yahoo.fr
Fri Aug 29 21:20:15 CEST 2014


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



More information about the R-help mailing list