0

I noticed that when I run a long command in linux (I am using a cantos 7.3 distro, R 4.0.3 on the terminal) and that I pipe to head only the first outputs are shows to me (and the command stops)

ls -R /opt        # on my system I would get tons of output for 10s of seconds
ls -R /opt | head # just get the top 5 and command is stopped straight away

when I try the equivalent in R I cannot get the same behaviour

system(command = "ls -R /opt | head") # will take a long time (I assume the time for ls -R /opt to finish)

Is there a way for me to get the same behaviour in R than the one I get on my system command line ?

statquant
  • 13,672
  • 21
  • 91
  • 162
  • I don't see a slowdown here (using macOS 10.15.7), running R from the command line or R.app. On RStudio it seems slower. What is your OS and which R frontend are you using? – user2554330 Dec 04 '20 at 13:20
  • how fast is the command you're running finishes if you do not pipe to head ? sufficiently long so there is a difference when you pipe to head ? – statquant Dec 04 '20 at 13:22
  • Using `/opt` isn't very slow, but using `/users` is quite slow without piping. Only see the slow pipe with RStudio. – user2554330 Dec 04 '20 at 13:25
  • (on windows) `system` doesn't honor the `|` piping mechanism, it's just another character passed to `ls` (and `ls` also sees `head` as an argument). (This isn't a factor on unix-like OSes) – r2evans Dec 04 '20 at 14:36
  • ok good to know thanks, but as I said I am on linux. So the question remains unanswered – statquant Dec 04 '20 at 15:07

0 Answers0