Is it possible to create an executable file where I can just upload the excels and an output is generated based on the coding and without sharing it as well.
On Linux or OSX you can make an R script double clickable with the shebang trick:
Add #!/usr/bin/Rscript as the first line
Make the script executable with chmod +x
On OSX, there is also the option to convert an R script into an application bundle with Platypus. On Windows, I do not know whether this is easily achievable at all, especially as executables usually are not placed in the search path on Windows.
is using R-Shiny apps can cover that? Its an R based program and you can customize the output / logic there.
Related
Current script
I work on Mac OSX. I have an R script that I like to use to organize my files and produce .pdf via LaTex. In order to (1) produce the .pdf with LaTeX and (2) manipulate some files and directories I use Bash script from R with system("").
From Mac to Windows
I would like to offer this R script (once compiled to make an executable) to someone that knows nothing about programming and uses Windows. I have no idea how the windows prompt commands work and what language it uses. I am afraid that (1) I cannot use the function system("") on Windows and (2) I cannot use bash such as system("rm dir/file.txt").
Question
What do you think would be the easiest for me in order to make my script compatible with Windows (given that I know nothing about Windows)? Will I be able to use system("") and Bash from R on Windows?
I think the best solution is to handle both cases separately (keep in mind that windows paths are also different from unix paths).
if(.Platform$OS.type == "unix") {
system("rm dir/file.txt")
[...]
}
else {
system("DEL /Q dir\file.txt")
[...]
}
You should have no problem searching for unix equivalent commands in windows cmd.
Also keep in mind that if you need the R script to exec LaTeX binaries, it would pretty much kill the portability because of the huge dependencies that LaTeX has.
I am new to using makefiles in R, so excuse the really simple question: How do I execute a makefile which resides in a folder using R?
Is there a way to do so using a .R script? If so, what would the command line include?
I found the following solution to my problem in calling make using R (assuming you use Windows and RStudio):
Turns out you first need to add Rtools to your PATH
Select Avanced System Settings / Environment Variables / System Variables New.
Add the following to PATH:
C:\Rtools\gcc-4.6.3\bin
C:\Rtools\bin
Now Reboot.
After this is done, reopen your R console. Now you can use #yihui's servr package, and call a folder containing a makefile as follows:
servr::make(dir="path containing Makefile")
Hope this helps other newbies to makefile too...
I am a newbie to UNIX, i want to print tree structure of files in a directory. below image is example in DOS, what will be the command of Unix to achieve same objective
I think you are looking for the "tree" command. If you are having issues running it you might have to find out how to install it on your specific distribution. For ubuntu installs you can find instructions here:
https://askubuntu.com/questions/507588/not-able-to-install-tree-comand-in-ubuntu
Not sure what you mean by "on Unix". What OS are you running, specifically? Tree should be compatible on Unix systems. You may just have to compile it for your particular OS.
This command prints output like the following (on cygwin):
I am interested in providing a command line interface to an R package called Slidify that I am authoring. It uses Rscript and I think that would make it cross-platform. The scripts are stored in the subdirectory inst/slidify. In order to use the script from any directory, I added its path to my .bash_profile as I am on a Mac.
My question is
How should I handle installation of the script in an automated cross-platform way?
How can I make sure that the file permissions are retained in this process?
What should the shebang line for the script be? I am currently using
#!/usr/bin/Rscript --vanilla --slave
I would appreciate pointers on how to handle this and any examples of R packages that already do it. Just to make sure, I am clear on how this would work, a user would be able to generate a slide deck from slides.Rmd by just running slidify generate slides.Rmd from the command line.
UPDATE:
Here is how I install it on a Mac from the command line. I use the excellent sub library by 37 signals to create the scripts.
echo "$(path/to/clidir/slidify init -)" >> ~/.bash_profile
exec bash
Two follow up questions
Can I package these commands into an R function install_slidify_cli?
How can I mirror these commands for Windows users?
Lovin' slidify so would be glad to help.
But in short, you can't.
R packages simply cannot install outside of $R_HOME or the chosen library folder. Ship the script in the package, and tell users to copy it. If there was a better way, out littler package with predecessor / alternative to Rscript would long have used it, and roxygen / roxygen2 would also have shipped something.
I have created a batch file to launch R scripts in Rterm.exe. This works well for regular weekly tasks. The < PBWeeklyMeetingScriptV3.R > is the R script run by Rterm.
set R_TERM="C:\Program Files\R\R-2.14.0\bin\x64\Rterm.exe"
%R_TERM% --slave --no-restore --no-save --args 20120401 20110403 01-apr-12 03-apr-11 < PBWeeklyMeetingScriptV3.R > PBWeeklyMeetingScriptV3.batch 2> error.txt
I've tried to modify this to launch the R GUI instead of the background process as I'd like to inspect and potentially manipulate and inspect the data.
If I change my batch file to:
set R_TERM="C:\Program Files\R\R-2.14.0\bin\x64\Rgui.exe"
the batch file will launch the R GUI but doesn't start the script. Is there a way to launch the script too?
Alternatively is there a way to save/load the work space image to access the variables that are created in the script?
You can save and load workspaces by using save.image() and load(). I do this all the time when scripting to pass data sets between two separate script files, tied together using Python or bash. At the end of each R script, just add:
save.image("Your_image_name.RData")
The image will be the workspace that existed whenever the command was run (so, if it's the last command in the file, it's the workspace right before the exist of the file). We also use this at my job to create "snapshots" of input and output data, so we can reproduce the research later. (We use a simple naming convention to get the time of run, and then label the files with that).
Not sure about launching and then running the GUI with specific scripts in it; I don't think that's a feature you'll find in R, simply because the whole point of running a batch file is usually to avoid the GUI. But hopefully, you can just save the image to disk, and then look at it or pass it to other programs as needed. Hope that helps!