Since R 2.13, R comes with a built-in web server.
Is there a simple way to create a local web server using R with a custom port number?
In python it will be (to use "http://localhost:8080") :
python -m SimpleHTTPServer 8080
I'm aware of Rook but I look for a simple solution.
Take a look at Rook - it's on GitHub. About setting a port number, see ?tools::help.ports it accepts a vector of numbers (integers) and it will choose the first available one. There's also sinartra (CRAN, GitHub), but I'd rather go with Rook.
It looks like servr might be what you're looking for these days.
From github:
To some degree, this package is like python -m SimpleHTTPServer or python -m http.server.
https://github.com/yihui/servr
https://cran.rstudio.com/web/packages/servr/index.html
Example code
writeLines("<h1>Hi</H1>", "index.html")
# install.packages("servr")
library(servr)
servr::httd()
# createTcpServer: address already in use
# To stop the server, run servr::daemon_stop(2) or restart your R session
# Serving the directory /Users/st/R/localhost at http://127.0.0.1:7826
Place the address in the browser: http://127.0.0.1:7826
This is not an answer, but some places to get started.
If we run R from terminal (by typing R), then run help.start(), it will start a local host and open it in the browser. On mine, it opens http://127.0.0.1:16371/doc/html/index.html. This at least proves that it's possible to open a localhost in R without any external packages.
I have found some of the code that makes this happen in the R Source Code.
Related
I'm started exploring MPTCP recently and started using it on my Ubuntu 18.04. My MPTCP version is 0.95. curl http://multipath-tcp.org on my terminal is returning Yay, you are MPTCP-capable! You can now rest in peace. I further checked it on http://amiusingmptcp.de/ which is telling me I'm using MPTCP. Now I want to write my own default scheduler. So I clicked on appropriate link on http://amiusingmptcp.de/ page which took me to http://progmp.net/progmp.html page. In this page it is showing that I'm not using MPTCP connection so the demo page is showing limited features. I have attached the relevant screenshots. Can someone please tell me how to make my own scheduler?
Thanks
It seems that you must be on multiple interface to do so. Also, for the local machine based setup without
internet (local network only) you can install the progmp kernel onto your own machine.
In order to do so in your terminal,
wget -c http://progmp.net/tools/linux-image-4.1.20-ProgMp.deb
# then
sudo dpkg -i linux-image-4.1.20-ProgMp.deb
to install the kernel
After that boot into grub menu and select the progMP kernel. the uname -a should prompt kernel version 4.1.20.
Now for writing your own scheduler you can download the example code from progmp.net site and use the python script to add it to the system.
here is the further documentation in order to proceed, along with detailed steps:
http://progmp.net/
I was wondering if writing to a protected samba directory, to a internal directory with another user/pass could be possible. I have been searching for an R package with these capabilities but I haven't found it yet. Now I'm using the write() function. In the documentation for this function, it says:
Arguments:
x : The data to be written out, usually an atomic vector.
file : A connection, or a character string naming the file to write to. If "", print to the standard output connection. If it is "|cmd", the output is piped to the command given by ‘cmd’.
I don't understand if the attribute "file" when writing "|cmd" launches the Terminal in Ubuntu server or something, but I can't make it work
Hope you have a nice day!
I found it can be done via a shell script in Ubuntu. The command is write(somefile, file = "|sh shellWriteSamba.sh")
Edit: The complete solution is in R - write() a file to a SAMBA share
I'm trying to use a Windows computer to SSH into a Mac server, run a program, and transfer the output data back to my Windows. I've been able to successfully do this manually using Putty.
Now, I'm attempting to automate the process using Plink. I've added Plink to my Windows Path, so if I open cmd and type in a command, I can successfully log in and pass commands to the server:
However, I'd like to automate this using R, to streamline the data analysis process. Based on some searching, the internet seems to think that the shell command is best suited to this task. Unfortunately, it doesn't seem to find Plink, though passing commands through shell to the terminal is working:
If I try the same thing but manually setting the path to Plink using shell, no output is returned, but the commands do not seem to run (e.g. TESTFOLDER is not created):
Does anyone have any ideas for why Plink is unavailable when I try to call it from R? Alternately, if there are other ideas for how this could be accomplished in R, that would also be appreciated.
Thanks in advance,
-sam
I came here looking for an answer to this question, so I only have so much to offer, but I think I managed to get PLINK's initial steps to work in R using the shell function...
This is what worked for me:
NOT in R:
Install PLINK and add its location to your PATH.
Download the example files from PLINK's tutorial (http://pngu.mgh.harvard.edu/~purcell/plink/tutorial.shtml) and put them in a folder whose path contains NO spaces (unless you know something I don't, in which case, space it up).
Then, in R:
## Set your working directory as the path to the PLINK program files: ##
setwd("C:/Program Files/plink-1.07-dos")
## Use shell to check that you are now in the right directory: ##
shell("cd")
## At this point, the command "plink" should be at least be recognized
# (though you may get a different error)
shell("plink")
## Open the PLINK example files ##
# FYI mine are in "C:/PLINK/", so replace that accordingly...
shell("plink --file C:\\PLINK\\hapmap1")
## Make a binary PED file ##
# (provide the full path, not just the file name)
shell("plink --file C:\\PLINK\\hapmap1 --make-bed --out C:\\PLINK\\hapmap1")
... and so on.
That's all I've done so far. But with any luck, mirroring the structure and general format of those lines of code should allow you to do what you like with PLINK from within R.
Hope that helps!
PS. The PLINK output should just print in your R console when you run the lines above.
All the best,
- CC.
Just saw Caitlin's response and it reminded me I hadn't ever updated with my solution. My approach was kind of a workaround, rather than solving my specific problem, but it may be useful to others.
After adding Plink to my PATH, I created a batch script in Windows which contained all my Plink commands, then called the batch script from R using the command shell:
So, in R:
shell('BatchScript.bat')
The batch script contained all my commands that I wanted to use in Plink:
:: transfer file to phosphorus
pscp C:\Users\Sam\...\file zipper#144.**.**.208:/home/zipper/
:: open connection to Dolphin using plink
plink -ssh zipper#144.**.**.208 Batch_Script_With_Remote_Machine_Commands.bat
:: transfer output back to local machine
pscp zipper#144.**.**.208:/home/zipper/output/ C:\Users\Sam\..\output\
Hope that helps someone!
I'm using a Windows 7 x64 machine with R-3.1.0. I installed the Rserve package through Rstudio.
The start of Rserve is successful with the following code in Rstudio:
library(Rserve)
Rserve()
I got the following output:
Starting Rserve...
"C:\R\R-31~1.0\library\Rserve\libs\x64\Rserve.exe"
My problem is that I couldn't locate the configuration file. Apparently it can't be "/etc/Rserv.conf".
I did come across a webpage saying that the config file is Rserv.cfg in the working directory (unless changed at compile-time). But which working directory? I have checked the working directory of the current R project as well as the Rserve library directory, but it was not there...Could someone help me with this please? Thank you.
Rserve does not automatically come with a config file, you must make one. Best steps for doing so:
Navigate to the file where you just installed Rserve.exe (C:\R\R-31~1.0\library\Rserve\libs\x64\R, based on the message you copied here)
Find Rserve.exe, Reserve_d.exe, and Rserve.dll there. Copy these files.
Navigate to where R.dll is on your computer. This is probably C:\Program Files\R\R-3.1.3\bin\x64, but may be different depending on where you installed R to.
Copy the 3 files mentioned above to this location.
Create a text file here named "Rserv.cfg" with the arguments you are looking for, such as port 6312 or library(mvoutlier). Yes, I know that this is different from the documentation, but if you start Rserve_d.exe you will see that this is the file it is looking for. I have not had success naming it anything else.
You can start Rserve by specifying the location of the config file. In R instead of just Rserve() try the following:
Rserve(args="--RS-conf C:\\folder\\Rserv.cfg")
If path is more complicated you need to massage it a little bit:
Rserve(args="--RS-conf C:\\PROGRA~1\\R\\R-215~1.2\\library\\Rserve\\Rserv.cfg")
Look in the $RHOME/bin directory
If you can't find it here is a different way to approach it:
Download Rserve at [http://rforge.net/snapshot/Rserve_.tar.gz], and save it in your desired directory
Run R CMD INSTALL Rserve_.tar.gz
This allows you to leave Rserve where you want it.
After looking at the Rserve source code and making some test I found that on Windows platform Rserve try to load the configuration file from the current working directory. Also pay attention because on Windows the file name is RServ.cfg and not Rserv.conf as documented.
The current working directory depends of the process, for example using RStudio by default it is your Documents and Settings folder:
C:\Users\[username]\Documents
but can be changed in the "Global Options" of the IDE
So you can create an "RServ.cfg" text file in that directory with your needed options and starting RServe in the usual way in RStudio
Rserve()
will load your configuration.
I'm trying to understand how openmpi/mpirun handle script file associated with an external program, here a R process ( doMPI/Rmpi )
I can't imagine that I have to copy my script on each host before running something like :
mpirun --prefix /home/randy/openmpi -H clust1,clust2 -n 32 R --slave -f file.R
But, apparently it doesn't work until I copy the script 'file.R' on clusters, and then run mpirun. Then, when I do this, the results are written on cluster, but I expected that they would be returned to working directory of localhost.
Is there another way to send R job from localhost to multiple hosts, including the script to be evaluated ?
Thanks !
I don't think it's surprising that mpirun doesn't know details of how scripts are specified to commands such as "R", but the Open MPI version of mpirun does include the --preload-files option to help in such situations:
--preload-files <files>
Preload the comma separated list of files to the current working
directory of the remote machines where processes will be
launched prior to starting those processes.
Unfortunately, I couldn't get it to work, which may be because I misunderstood something, but I suspect it isn't well tested because very few use that option since it is quite painful to do parallel computing without a distributed file system.
If --preload-files doesn't work for you either, I suggest that you write a little script that calls scp repeatedly to copy the script to the cluster nodes. There are some utilities that do that, but none seem to be very common or popular, which I again think is because most people prefer to use a distributed file system. Another option is to setup an sshfs file system.