3

I have a CSV file and I want to work on it I've tried to read it by using this code

d = read.table( pipe( 'ssh don@140.184.134.189 "cat cluster.csv"' ), header = T )

But I get no result and get this message:

"error in read table"

Without asking about my password.

Also, how do you run an R script fes.r that is located on the same server?

Michael Oryl
  • 20,856
  • 14
  • 77
  • 117
Don Coraliony
  • 31
  • 1
  • 4
  • 1
    Maybe mounting the directory first is the best solution. This can be done using `sshfs`. Theoretically you could also execute the mount command from within R with `system()` – jakob-r Feb 28 '15 at 15:55

3 Answers3

2

You can first try this, continuing along the lines you are on:

> d <- read.table(pipe('ssh -l don 140.184.134.189 "cat cluster.csv"'))
don@140.184.134.189 password: # type password here

If you don't get prompted for a password, then there is likely a configuration problem with your ssh. Please note that ssh has to be installed and in your $PATH (meaning R can invoke it from anywhere it is running).

If this option doesn't work, then you can try using scp from the RCurl package.

Try the following:

x = scp("140.184.134.189", "cluster.csv", "PASSPHRASE", user="don")

Here you should replace "PASSPHRASE" with the password of your local SSH key.

One other thing to check is whether "cluster.csv" is really the correct path to your file on the remote server. But it seems that you are not even getting this far, so fix the ssh problem first.

Hat tip to this Stack Overflow post for inspiration.

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • I insalled the RCurl package when I ran this code x = scp("140.184.134.189", "cluster.csv", "PASSPHRASE", user="don") I got this message Error: could not find function "scp" In addition: There were 21 warnings (use warnings() to see them) – Don Coraliony Feb 28 '15 at 17:37
  • Did you try installing `RCurl` using the commmand `install.packages("RCurl")` ? – Tim Biegeleisen Mar 01 '15 at 00:42
  • in the first time i used the list to download this package then I used this code and I got this message nstalling package into ‘/Users/badrmansour/Library/R/3.1/library’ (as ‘lib’ is unspecified) inferring 'repos = NULL' from 'pkgs' trying URL 'http://cran.mtu.edu/bin/macosx/mavericks/contrib/3.1/RCurl_1.95-4.5.tgz' Content type 'application/x-gzip' length 718964 bytes (702 Kb) opened URL I download this packge from R site and I dont know what I have to do right now – Don Coraliony Mar 01 '15 at 15:04
  • Can you try typing `require("RCurl")` in your console and let us know what you see. If RCurl is not installed, or if any dependencies be missing, R should output this. – Tim Biegeleisen Mar 01 '15 at 15:13
  • I got that require("RCurl") Loading required package: RCurl Loading required package: bitops – Don Coraliony Mar 01 '15 at 15:24
  • OK, so it looks like you have `RCurl` installed in your console now. Can you try running the `scp` function call given above again? – Tim Biegeleisen Mar 01 '15 at 15:45
  • thanks now it is working; however I got this message Error in function (type, msg, asError = TRUE) : Protocol scp not supported or disabled in libcurl – Don Coraliony Mar 01 '15 at 16:28
  • You can get this error from using the wrong `ssh` connection. Can you check your host, username, and passphrase to make sure your `ssh` connection be valid? – Tim Biegeleisen Mar 02 '15 at 00:51
1

You could take a different approach and install Rstudio server on your remote linux machine.

Rstudio server

Minnow
  • 1,733
  • 2
  • 26
  • 52
1

You can avoid the password problem by setting up an ssh key pair, and adding your public key to the ~/.ssh/authorized_keys file on the server.

You can see how to run an R script from command line here: Run R script from command line

Community
  • 1
  • 1
Balint Domokos
  • 1,021
  • 8
  • 12