Mike.Gahan
Mike.Gahan

Reputation: 4615

Calling Linux functions from R

I have been using the system function within R as part of my workflow to call Linux commands. One item that is puzzling to me is that certain functions seem to work and others do not.

For example, if I call system("ps") within R, it gives me a list of process ids, Time, and the Cmd.

But if I invoke system("top"), I get the following error:

TERM environment variable not set.

Anyone know how to fix this? My workflow consists of running RStudio server from a browser that sits on a Windows box. It is conveinient for me to not have to open up PuTTy in order to keep tabs on R processes.

Upvotes: 0

Views: 202

Answers (2)

kith
kith

Reputation: 5566

If you run top in 'batch' mode you can use it in a system call.

system("top -n 1 -b")

The -n 1 option runs a single iteration

the -b option runs in batch mode instead of interactive

Upvotes: 2

cdeterman
cdeterman

Reputation: 19950

As per the error message, the TERM environmental variable is not set. Try to set it with Sys.setenv

Sys.setenv(TERM = "xterm")

Upvotes: 1

Related Questions