R Tensorflow installation with no user input in console - r

I have a basic script in R 4.1 and R Studio which installs TensorFlow 2.
When I run the library installation for Tensorflow, everything works fine with no issues. My issue is that when I call the library and run the install_tensorflow command, the console is asking me to answer a "yes/no" question.
Would you like to install Miniconda? [Y/n]:
My question: How do I answer this with a Y without having to type directly into the console? I want to just run an R Script to install and provision my conda environment without manual intervention. Programmatic User Input.
Here is my full R code:
install.packages("tensorflow")
library(tensorflow)
install_tensorflow(method="auto", conda="auto", version="2.0.0", envname ="tf_test")

Related

Running R from Excel using specific old R packages

First time question asker.
I created an Excel/R tool that uses:
Excel VBA to create a CSV file with data for R,
Launch R using a Windows Shell,
Detects when R is finished running and then
Imports the results in a CSV file created by the R script.
Unfortunately, the R code does not work as programed with some package versions created after 3/1/2020, which creates problems for new users because they cannot just install the current package versions or users who want to use conflicting versions for other projects.
I have a solution for users who do not require newer versions of R for their other work; writing a script that installs all the packages and their dependents using the “versions” package. However, I think this approach will constrain users who want to use newer versions of R. **Is this a correct assumption? **
I thought the {checkpoint} package might offer a good solution. I can get it to run in well in RStudio by creating a RStudio project (where I ran the {checkpoint} package to install the 3/1/2020 versions of my packages). However, I have not found a way to run the R script from the Windows Shell. The R script does not seem to be able to access the packages installed in the RStudio project using {checkpoint}. Does anyone have ideas of how I can have Excel VBA launch the start of the R script in a way that it can assess the packages installed in the RStudio project by {checkpoint}? Perhaps there is a Windows Shell call for RStudio similar to the one I use now for R?
Here is the Windows Shell code I currently use for R in case it helps. It works with the versions approach but not the {checkpoint} approach.
rExeCall = "C:\Program Files\R\R-3.6.2\bin\Rscript.exe"
rExeOptns = " --no-environ --no-init-file --no-restore --verbose "
rscrpt=”Tool.R”
Shell (rExeCall & rExeOptns & rscrpt)
Thank you in advance for your help!
I had hoped that my current R shell code would work when I used {checkpoint} to install the correct versions of the packages in an RStudio project.
I tried specifying the .libPaths to the file location for the RStudio projection (per Running R script from PHP in VSCode not recognizing R packages) without success.

How to install package keras in R

I'm trying to install deep learning package keras on RStudio using this website. I installed keras using
install.packages("keras")
library(keras)
install_keras()
but when I tried to open the MNIST dataset
mnist <- dataset_mnist()
I keep getting the error
Error: ModuleNotFoundError: No module named 'absl'
I thought keras installed tensorflow but do I need to install tensorflow separately?
I had the same problem and it is solved by installing the package in two steps:
install keras: install.packages("keras")
keras::install_keras()
There you go!
If you follow the TUT and still got error, try running py_config() and check the python and libpython if it is pointing to an r-tensorflow environment. If not, best to try manually install keras in your manually set up conda environment.
Step 1: Install keras in your R just like in the link above.
#Open rstudio and run the following command
devtools::install_github("rstudio/keras")
#Don't close rstudio after running this, okay?
Step 2: Manually install keras (and tensorflow) in your machine ##. When i say “manual” it means using python specifically through conda. Here’s the link I followed: https://medium.com/i-want-to-be-the-very-best/installing-keras-tensorflow-using-anaconda-for-machine-learning-44ab28ff39cb .
In summary, the link will teach you to install anaconda, create an environment and install necessary libraries. Just follow it. I named my environment as “r-tensorflow” because that is the name of the environment that the install_keras() in R will do :)
Step 3: Point rstudio to use the python in your newly created environment using use_python() function
Open your rstudio (if you close it after following step 1) and type the following code
library(keras)
library(reticulate)
# in case you run into error run this : reticulate::py_discover_config("keras")
use_python("<yourpath>/Anaconda3/envs/r-tensorflow/Scripts/python.exe")
# change <yourpath> approriately
# write all the codes for building model in keras (or tensorflow) e.g. mnist<-dataset_mnist()
Important note on Step 3: If you still got the "not found module" after following step 3, you must start a new fresh R session and ensure to delete the workspace (.RData) because more likely your current script will still use the old python configuration though you used use_python
I had the same problem, but mine was solved by enclosing keras in double quotes.
install.packages("keras") ## worked for me,
install.packages(keras) ## never worked.
try:
install.packages("devtools")
devtools::install_github("rstudio/keras")
library(keras)
mnist<-dataset_mnist()
Please install "reticulate" library using command install.packages("reticulate") and then load using library(reticulate)
then install absl using command
conda_install('r-tensorflow','absl-py')

Installing R on Apache Zeppelin

I'm trying to install Apache Zeppelin on my old computer that runs Ubuntu. So far, I'm able to install Zeppelin very easily by cloning the latest 0.6.0 snapshot release using
git clone https://github.com/apache/incubator-zeppelin.git
cd incubator-zeppelin
mvn clean package -DskipTests
but I want to have R on Zeppelin. Supposedly, the 0.6.0 snapshot has two R interpreters, but when I run the R tutorial (the pre-made note that uses %r), I get this list of errors.
I followed several guides to try and install R as an interpreter, but each one resulted in some kind of error. I tried this instructional:
http://www.r-bloggers.com/interactive-data-science-with-r-in-apache-zeppelin-notebook/, and got a build failure on "R Interpreter". The error message was
"dependency 'evaluate' is not available for package 'rzeppelin'
* removing '/home/rebecca/Zeppelin-With-R/R/lib/rzeppelin'"
and then a bit lower down
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default) on project zeppelin-zrinterpreter: Command execution failed. Process exited with an error: 1
I also tried this Stack Overflow guide: Anyone tried to add R interpreter onto Apache Zeppelin?, and while I was able to run incubator-zeppelin, I received an error when I used either the %spark.r or %r interpreter tags, saying both "interpreter not found" and "prefix not found". Spark doesn't work either after following the first solution, getting the same error mentioned in the second solution (the jar file not being there), and then trying the second solution.
Does anyone have a guide for installing R onto the newest version of Zeppelin? I'm very flexible in the way I can install it. I can run other operating systems onto my computer, and I also have Virtual Box installed on my other computer, which is a mac.
There is currently a bug in the latest HEAD of zeppelin that was recently introduced and prevents the R interpreter from launching cleanly
Did anyone created a Zeppelin Jira Issue for that?
For me it is working on Zeppelin branch-0.6
build Zeppelin with r profile: -DskipTests -Prthis will...
create a directory 'R' in git repo root
copy the 'zeppelin-rinterpreter*.jar' into git_repo_root/interpreter/spark
build Zeppelin with build distro profile: e.g. -DskipTests -Pbuild-distr -Pspark-1.6 -Phadoop-2.6
use zeppelin-distribution/target/zeppelin*.tar.gz for installation
ensure both 1.1 and 1.2 are present in your zeppelin installation
The error you're getting is that you need to have the R package evaluate installed. You can install this simply by launching R and typing install.packages('evaluate').
That said, your excerpt mentions the directory Zeppelin-with-R. That's my repo, which is the R interpreter in the form when it was accepted into Zeppelin. That is version 0.5.6, not 0.6.0. There is currently a bug in the latest HEAD of zeppelin that was recently introduced and prevents the R interpreter from launching cleanly. Your best bet for now is to use the one from my repo and install clean, without trying to pull-in from Zeppelin HEAD.

Run R (from pkg) in terminal on OS X

I just installed MacOS version of R from the CRAN web site. Within the R GUI application, everything works fine. However, I'm unable to run it from terminal. Trying to trigger R or Rscript in terminal yields a message indicating that neither command exists.
Also I do not see corresponded scripts in /Applications/R.app/Contents/.
How can I run R from terminal?
PS: I know brew installation will help. But I want this version of R from CRAN web site.
The R installer creates /Library/Frameworks/R.framework/ directory in addition to /Applications/R.app/.
So, you need add a correct directory to the Library dir. For my packages:
R_APP_DIR=/Library/Frameworks/R.framework/Versions/3.2/Resources/
export PATH=$R_APP_DIR:$PATH

specifying R library path for RKernel in Anaconda Jupyter notebook

First let me preface this with the disclaimer that I'm new to R, but a longtime Python power user. Given that I love the conda ecosystem and the Jupyter notebook, I'm trying to set them up as my R development environment as well.
So using the instructions at: https://www.continuum.io/blog/developer/jupyter-and-conda-r I've set up a Jupyter Notbook that using an RKernel that should be hitting the installation of R installed in my Anaconda folder (I would think anyway).
Getting it setup was easy peasy and everything is working great for standard R stuff but my analysis requires some R libraries that are not available in r-essentials channel. No problem, I think I know how to install an R library. I go to "C:\Anaconda\R\bin\x64\Rgui.exe" and install rgdal, dismo, and some other packages. To check my work I looked in C:\Anaconda\R\library and there they are.
But when I run a jupyter notebook from the Anaconda command prompt. And start a new R notebook I get a "Error in library(dismo): there is no package called 'dismo'" Wait a sec, I run a ".libPaths()" from the notebook and it looks like its pointing
You can add .libPaths('path_where_your_packages_are') in a code cell at the beginning of your notebook to tell jupyter where your packages are. For me that was .libPaths('~/R/win-library/3.2') (work-around from discnerd who filed this issue on github).
To find out the path to your packages, just install a random package in R and wait for the location to be printed to the console.
More details (likely specific to my system/installations): When running .libPaths() in R, I got 2 locations: one for which admin rights were required for writing, and one for which admin rights were not required for writing. While packages installed through R land in the location where admin rights are not required, jupyter looks at the location where admin rights are required.
You can find out the path to your library with installed.packages()

Resources