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