How can I use system or system2 if the command has pipe to head like "cmd | head"

442 views Asked by At

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 ?

0

There are 0 answers