Enter passwords interactively in R or R Studio (Server)? - r

Is there a way in R to enter passwords interactively to the command line and hide them from the screen? I know there's readLine, but I do not know passwords can be hidden there.
Assume you want to connect to a database using ROracle or RMySQL and do not want to store the password in a script but rather make the user enter it every time a query is executed.
Yes, we had a similar question around here, but I feel that the situation has changed and it's worth to address to problem again. Unfortunately tcltk won't work on RStudio (Server).
However I have seen the folks at R Studio found a solution for their version control support. I remember previous versions where I could see my repo password every time I enter it in R Studio, but now that seems to be fixed. I know it's likely R Studio technique, but is there a way mortal R users can access it when working with R Studio Server?

Actually R Studio (Server) provides a nice solution. You can access it by using .rs functions. They provide an undocumented password function which is really nice though there's no guaranteed support forever and a day:
.rs.askForPassword("foo")
You can find the the original hint from RStudio's Josh here:
http://support.rstudio.org/help/discussions/questions/1448-password-interaction-with-dbs-on-rstudio-server
EDIT:
As of 2015 there is another nice solution to enter password interactively. You could use shiny to have a little web based window with a password form. This discussion I had with #hadley shows an example snippet: https://github.com/rstats-db/RPostgres/issues/26
EDIT:
As of 2017 there is another update to this. #m-dz pointed us to this:
rstudioapi::askForPassword("Enter your pw") as well as getPass::getPass() from the R Studio Support webpage. Plus, I also realized that there is .rs.api.askForPassword() which is equivalent to the initially suggested call - at least as far as I've seen.

Related

Alternative place to run my R code with more than 1GB RAM over RStudio Cloud

For some reason, my RStudio constantly crashes on start up in my windows laptop and I have an important assignment to be written in R soon. Are there any alternatives to RStudio that I can use to do this? My task takes over 1gb RAM which is just over the RStudio cloud limit hence I am unable to use that too.
I've gotten all the codes written down, just need to put them onto the Rstudio. If anyone wouldn't mind downloading the file, put my code down and send me a screenshot of the output, please let me know!
Thank you
Visual Studio Code
I second the comment that it probably is not Rstudio that causes the problem. But to answer your question:
Visual studio code has an extension for R, that would give you a quite similar experience.
At these links you can read more about the R extension and visual studio code
Edited to link to the most popular R-package.

RStudio R File Corruption

I had a R script open in RStudio. The file was saved many times over the course of several weeks and worked perfectly fine when RStudio was opened and closed. However, today, I restarted my computer and when I opened RStudio and more specifically the script that I mentioned, all of the R code vanished, leaving a single long row of "....." with red highlighting.
When I tried to open the R file in other text processors such as Sublime Text and Notepad++, only a line of zeroes was visible. None of my other R files were affected. I'm currently running Windows 8.1 and have the latest version of R and RStudio. What can I do to recover the code in the file and prevent something like this from happening again?
It might be an old thread and it might have been covered in 'user4458796' answer in suggestion #1 ("Use the history..."), but:
My friend had the same problem and we managed to recover the code from a 'history_database' files located on Windows at:
'C:\Users\%user%\AppData\Local\RStudio-Desktop\'
I assume there is an equivalent location in Linux in general.
Hopefully I won't get downvoted, just sharing my 2cents.
Ben.
It's not clear what happened to corrupt your file (and thus how to fix it if possible) and it is kind of ominous that you're just seeing 0's in other text editors, but I'll give you my best suggestion and some tips.
Suggestions for Attempting Recovery
Since your other R files were unaffected, you should have a messy record of your code in the history. Use the history to reconstruct your code.
Access a copy of your file from any version control, cloud, or offline backup you may have used -- git, SVN, iCloud, SugarSync, Dropbox, etc (I realize you probably wouldn't have posted this question if that were an option, but I had to throw it out there).
Use a Hex or sector editor to try to recover the data.
Use a data recover program to find an old version of your file.
Inspect your trash or recycling bin to see if it has an old version. Depending on your OS and the settings of how you (insecurely or securely) delete files, then you may be able to undelete a deleted version, even if it's not immediately available.
Try different methods of recovering text data from corrupted text files like OpenOffice's and Microsoft's suggestions.
Tips for the Future
I know that hindsight is 20/20, but a few quick tips for good measure:
Use version control. Git is supported in RStudio's GUI interface.
Have more than one version of your file. Many professors and professionals recommend writing/storing code in a text editor and using your IDE only for the working copy.
Make backups. Distinct from #2, you should backup your files to a hard drive, flash drive, or cloud service like Dropbox or Spideroak.

Refresh R console without quitting the session?

I usually open the R console all day long, but sometimes I need to clean my history and my workspace's background so that I can test functions or load new data.
I'm wondering whether there is an easier way to use a command line in .Rprofile so that I can refresh the R console without quitting or rebooting my current session.
What I have usually done for this is to q() without saving and then start R again and clean the History. I think somebody here might be able to give me some better suggestions.
Thanks in advance.
For what concerns history, in UNIX-like systems (mine is Debian) this command refreshes it
loadhistory("")
However, as said in comments, loadhistory seems to be platform-dependent.
Check your ?loadhistory if present on your platform. Mine says:
There are several history mechanisms available for the different
R consoles, which work in similar but not identical ways. There
are separate versions of this help file for Unix and Windows.
The functions described here work on Unix-alikes under the
readline command-line interface but may not otherwise (for
example, in batch use or in an embedded application)

Couple of basic questions about Julia on Windows

I run Julia on Windows with the julia.bat file given in the zip archive. I have a couple of basic questions. This launches a DOS console.
When typing a plot() command Julia returns plot not defined. How to use the plot() function ? Is there a graphical interface available ?
When typing help I get:
What does it mean ?
There is also the launch-julia-webserver.bat file in the zip archive. When running this file two DOS windows open but nothing else happens. What can we do with this file and how ?
By the way I do not find any documentation answering such basic questions... of course if you know where to find such a documentation it would be an ideal answer.
To answer your immediate question, help is implemented as a function, and functions must be called with parentheses. Try help(), or to get help for a particular function in the standard library supply it as an argument; i.e., help(help).
When you enter a function name without the parentheses, the default is to print all of the implementations with their argument types.
The main Julia documentation is available online at http://docs.julialang.org/. We also have a mailing list at https://groups.google.com/forum/#!forum/julia-dev.
The webserver is pretty rough, especially on Windows. You should be able to open up http://localhost:2000/ with it running and access a web-based command environment. But you'll probably just want to stick to the normal command line.
Another contributor highlighted the response to help as a potential issue for new users and we've opened a bug on it at https://github.com/JuliaLang/julia/issues/1320. It's a new language and there's still plenty of rough edges, so thanks for helping us file those down!
To use launch-julia-webserver.bat, after you double-click it and the two DOS windows open, one of them should say "Connect to http://localhost:2000/ for the web REPL". If you open a web browser to http://localhost:2000/, you should be greeted with a welcome page that asks for your name and a session name.

Tools Commonly used to Program in R

I apologize if this has already been asked a different way but I couldn't find anything getting at what I wanted.
I am really getting into R from other packages (SPSS). As I learn about what truly can be done, I realize that there are additional "tools" that I need. This gets me to my question.
What setup do you have for developing R code? I can't see myself actually developing r packages anywhere in the near future, but I do see myself wanting to manage my r projects effeciently, as well as create reports and presentations in LaTeX.
For context, I develop my R code in Eclipse for Windows, but I have had a real hard time successfully setting up Latex/Sweave and Github plugins.
Lastly, do you develop code using Windows or something else?
Many thanks in advance for any insight you can lend.
Emacs has everything I commonly need:
ESS (for R),
AucTeX (for Latex),
similarly rich 'modes' for other languages I use (C++, make, shell, ...),
plus a lot of other modes you get quite used to as e.g. dired for directory/file browsing or org-mode as planner/to-do list,
the SVN integration is very good too
and there are probably a number of tools within Emacs I am now forgetting.
Works in text mode as well as graphical mode, and works essentially the same (incl ESS and AucTeX) on several operating systems (Linux mostly and Windows when I must). On Debian/Ubuntu all this is prepackaged and tends to work out of the box as well. For both Windows and OS X, Vincent Goulet has package very handy bundles, see here.
The 'daemon mode' is outstanding too -- I keep the same main Emacs session running and just connect and re-connect to it even when accessing the machine (via ssh or directly) from different computers.
Also see the EmacsWiki for more tips around Emacs.
Back to Emacs and R in particular. The R FAQ says it pretty well:
6.1 Is there Emacs support for R?
6.2 Should I run R from within Emacs?
and I like the affirmative and resounding answer to the second question: "Yes, definitely". I fully concur.
I'll second the suggestion that Emacs compliments R nicely, but let me share what the "killer feature" is for me.
Using Org-mode with Org-babel, I can write whole reports with inline graphs produced from R in raster and vector format which compiles seamlessly into a PDF report via latex. I can also view the graphs while editing, similar to a WYSIWYG editor.
I just wrapped up a major report with over 70 inline graphs with little effort, no editing external files, no issues maintaining naming between figures in my report and external files, or forgetting to recompile the latest version of a figure. Org & Babel does it all.
Org-mode:
http://orgmode.org/
Org-Babel:
http://orgmode.org/worg/org-contrib/babel/index.php
Example of inline R with Babel and PDF output, see the first example in multiple formats:
http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-R.php
Enjoy!
This is probably more relevant for package development, but it is also worth mentioning the roxygen R package that allows in-source documentation of your code. Note that even though you can't see yourself developing R packages anywhere in the near future, a package can be a very handy way of grouping related functions you develop and maintain, consistently documenting the code and keeping track of updates, even if you do not plan to distribute it.
I use a mac, and my most important tools are:
the command line, for running R
git, for keeping track of changes
github for publishing my code, bug tracking and collaboration
textmate for writing R code
Has anyone tried RStudio? It's the shiny new editor for R.
I use windows... (don't say it).
I like Notepad++ and NPPtoR. Makes it pretty easy to send things back and forth.
I use Eclipse on Windows and Linux. I compile LaTeX code (with Sweave) on Linux and I haven't bothered yet to set up the whole process in Eclipse. I need to pdflatex and bibtex files several times anyway, so I just have a terminal window with the specific string of commands handy. I tried ESS and Eclipse and they're very similar in functionality (and in my opinion the best two editors out there).
I use Eclipse / StatEt on Windows, and it Rocks !. For LaTex/Sweave I use MikTex which works well for me. For help setting things up check out this document and this post.
Other Tools you may find useful include;
If you want to build R Packages on
Windows, then get the RTools
For
Creating Documents, you may want to
check out odfWeave,
LibreOffice (was OpenOffice) and
the MSOffice ODF plugin
I have also
dabbled with Git but also didn't get
very far on Windows, but that was a
while ago.
For Presentations in LaTex
I recomend Beamer
I use Eclipse for both R and Latex while working on research papers. The plugins for both are very mature now. The nice thing is that you don't have to switch application while writing papers. I used different combination before but I found this to be the best.
I just got home from our local R User meeting (find one near you here) and of the 20 or so people there, all of us used a different program or tool to write R code in. I think that goes to show the diversity of the tools used to write and edit R code is just as diverse as the R community itself.

Resources