I am using R on my work computer inside of our Network. Naturally, I do not have admin rights and It would be hard to convince my IT Department to make an exception for me installing Rtools on my computer.
My main issue with not having Rtools is, that I cannot use the saveWorkbook command from openxlsx, which would allow me to save data as Excel table objects.
The Error of the command implies that I could use an alternative zip application:
Please make sure Rtools is installed or a zip application is available to R
Would this be possible? Our work Computers have 7-zip for instance.
In line with the comment of #Tung and others I copied a Folder of Rtools from my private Computer to my work Computer. I tried the following to no avail
Rtools.bin="C:\\Rtools\\bin"
sys.path = Sys.getenv("PATH")
if (Sys.which("zip") == "" ) {
system(paste("setx PATH \"", Rtools.bin, ";", sys.path, "\"", sep = ""))
}
I also tried using Sys.setenv("R_ZIPCMD" = "C:/Program Files/7-Zip/7zG.exe") to use 7 zip but then I get an error messan Incorrect Switch postfix: -r1
I am specifally trying to replicate the writeDataTable example from openxlsx
Related
A friend has created this file: "their_tar_0.1.tar.gz". He told me that i can install it locally from this file alone, so i did via:
install.packages("their_tar_0.1.tar.gz", repos = NULL)
This worked absolutely fine with no issues. My issue is: I'd like to be able to host this on github publicly. I've saved this file within my github account in the regular format as: "author/package", i.e. "my_github_acc_name/their_tar_0.1". However, it seems that .tar.gz file is actually in the 'master' branch of this repo. Either way, when i try to install it via:
install_github("my_github_acc_name/their_tar_0.1")
or
install_github("my_github_acc_name/their_tar_0.1.tar.gz")
or
install_github("my_github_acc_name/their_tar_0.1\their_tar_0.1.tar.gz")
Which gives me the following error when i run it in RStudio:
*Downloading GitHub repo my_github_acc_name/their_tar_0.1#master
Error: Failed to install 'their_tar_0.1' from GitHub:
Does not appear to be an R package (no DESCRIPTION)*
Any ideas what my problem is? I've looked at the package and various questions online, however none of the questions seem to relate specifically .tar.gz file types.
Any help would be greatly appreciated.
Thanks, Dave
https://rawgit.com/rstudio/cheatsheets/master/package-development.pdf
From help("install.packages"):
Usage
install.packages(pkgs, lib, repos = getOption("repos"),
[... some content omitted ...]
pkgs character vector of the names of packages
whose current versions should be downloaded from the repositories.
If repos = NULL, a character vector of file paths,
on windows,
file paths of ‘.zip’ files containing binary builds of packages.
(http:// and file:// URLs are also accepted
So, you can just do
user <- "my_github_acc_name"
repo <- "their_tar_0.1"
branch <- "master"
fname <- "their_tar_0.1.tar.gz"
pkg_url <- paste("https://raw.github.com", user, repo, branch, fname, sep = "/")
install.packages(pkg_url, repos = NULL)
I recently updated R to the latest release: 3.4.0. R is installed on a network location H:/. Now something weird is happening when I try to install a local binary package:
filename <- paste0("R:/path/independeR_", versions, ".zip")
install.packages(filename,
repos = NULL, type = "source",
lib = gsub("\\\\\\\\networkpath/home/[[:alpha:]]*/",
"H:/", .libPaths()[1]))
Both H:/ and R:/ are network locations. In .libPaths() the default location is in the H:/ location, but it shows with the entire network adress. In the call to install.packages I substituted this.
The code above fails, with the following output:
'\\networkpath\home\JDUB~PN6\DOCU~UZL\R\R-34~TN4.0' is not recognized as an internal or external command,
operable program or batch file.
Warning in install.packages :
running command '"//networkpath/home/JDUB~PN6/DOCU~UZL/R/R-34~TN4.0/bin/x64/R" CMD INSTALL -l "H:\Documents\R\R-3.4.0\library" "R:/path/independeR_0.1.8.zip"' had status 1
Warning in install.packages :
installation of package ‘R:/path/independeR_0.1.8.zip’ had non-zero exit status
There is two things that surprise me here. The directorynames are all jumbled up (DOCU~UZL instead of Documents etc), but for some reason Command promt seems fine with that. The more interesting thing is the following:
When I try to put the command "//networkpath/home/JDUB~PN6/DOCU~UZL/R/R-34~TN4.0/bin/x64/R" CMD INSTALL -l "H:\Documents\R\R-3.4.0\library" "R:/path/independeR_0.1.8.zip" directly into Command Prompt, the output is very similar:
C:\Users\jdubbeldam>"//networkpath/home/JDUB~PN6/DOCU~UZL/R/R-34~TN4.0/b
in/x64/R" CMD INSTALL -l "H:\Documents\R\R-3.4.0\library" "R:/path/independeR_0.1.8.zip"
'\\networkpath\home\JDUB~PN6\DOCU~UZL\R\R-34~TN4.0' is not recognized as
an internal or external command,
operable program or batch file.
For some reason CMD seems to cut off the path to the command halfway through. I guess that this is because the command is too long. When I try the same command, but with H:/Documents/R/R-3.4.0/bin/x64/R, the installation goes just fine.
I would like to be able to automatically install this package from a script, so I would like a solution to this problem from within R. Is there a way to get R to use the shorter H:/Documents/R/R-3.4.0/bin/x64/R?
I was having problems with updating packages, while searching I found that there is a reported bug affecting getting the timestamps from files in Windows 10:
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17261
Starting in R 3.4.0, file.info sometimes returns for mtime,
atime and ctime for directories. It seems to have something to do
with sharing. This affects functions that use file.mtime like
update.packages.
Reproduce:
Try file.info() with a random directory. If it returns a legitimate
file time, open a windows explorer window and navigate to the
directory, then run the call again and it will return s.
In some cases it returns s even if the directory is not open (or
in the path of an open explorer window), but this is not consistent.
With a comment of Tomas Kalibera:
Thank you for the report, this is a known bug that has been fixed
recently in R-devel
I found that when I closed the file explorer windows the timestamps worked correctly and didn't show up as NA's.
This may be a lead for why your code isn't working.
I managed to make the following work. However, I think it is extremely ugly, and would still like to see if it is possible to do it someway else.
filename <- paste0("R:/path/independeR_", versions, ".zip")
cmd <- file.path(gsub("//networkpath/home/[[:alnum:]]*/", "H:/",
gsub("//networkpath/home/[[:alnum:]]*~[[:alnum:]]*/",
"H:/", R.home())), "bin/x64/R")
libname <- gsub("\\\\\\\\networkpath/home/[[:alpha:]]*/",
"H:/", .libPaths()[1])
call <- paste(paste0('"', cmd, '"'),
"CMD",
"INSTALL",
"-l",
paste0('"', libname, '"'),
"--no-lock",
paste0('"', filename, '"'),
sep = " ")
system(call)
To avoid the irregular parameter error caused by the directory including space and set workspace and tool path at once, I tried to compile R package in R console. My goal is compile the new version of "text2vec-0.4" which downloaded from https://github.com/dselivanov/text2vec/tree/0.4
setwd("E:/packbuild/")
builder <- "D:/Program Files/R/R-3.3.1/bin/x64/Rcmd.exe"
para <- "INSTALL --build"
packname <- "text2vec-0.4"
system(paste(shQuote(builder), para, packname, sep = " "), wait = FALSE)
When I run this program, it runs “successfully” no errors or warnings, but when I check the workspace"E:/packbuild/", there is no zip files generated and no new files installed in the R library. Rtools has completely installed in “D:/Rtools/” and its default path set has done.
Does Rtools can’t call by a meta program like this?
Or if we use command line, and don’t write directory of “Rcmd” into
path, how to do is right?
I want to deploy a basic trained R model as a webservice to AzureML. Similar to what is done here:
http://www.r-bloggers.com/deploying-a-car-price-model-using-r-and-azureml/
Since that post the publishWebService function in the R AzureML package was has changed it now requires me to have a workspace object as first parameter thus my R code looks as follows:
library(MASS)
library(AzureML)
PredictionModel = lm( medv ~ lstat , data = Boston )
PricePredFunktion = function(percent)
{return(predict(PredictionModel, data.frame(lstat =percent)))}
myWsID = "<my Workspace ID>"
myAuth = "<my Authorization code"
ws = workspace(myWsID, myAuth, api_endpoint = "https://studio.azureml.net/", .validate = TRUE)
# publish the R function to AzureML
PricePredService = publishWebService(
ws,
"PricePredFunktion",
"PricePredOnline",
list("lstat" = "float"),
list("mdev" = "float"),
myWsID,
myAuth
)
But every time I execute the code I get the following error:
Error in publishWebService(ws, "PricePredFunktion", "PricePredOnline", :
Requires external zip utility. Please install zip, ensure it's on your path and try again.
I tried installing programs that handle zip files (like 7zip) on my machine as well as calling the utils library in R which allows R to directly interact with zip files. But I couldn't get rid of the error.
I also found the R package code that is throwing the error, it is on line 154 on this page:
https://github.com/RevolutionAnalytics/AzureML/blob/master/R/internal.R
but it didn't help me in figuring out what to do.
Thanks in advance for any Help!
The Azure Machine Learning API requires the payload to be zipped, which is why the package insists on the zip utility being installed. (This is an unfortunate situation, and hopefully we can find a way in future to include a zip with the package.)
It is unlikely that you will ever encounter this situation on Linux, since most (all?) Linux distributions includes a zip utility.
Thus, on Windows, you have to do the following procedure once:
Install a zip utility (RTools has one and this works)
Ensure the zip is on your path
Restart R – this is important, otherwise R will not recognize the changed path
Upon completion, the litmus test is if R can see your zip. To do this, try:
Sys.which("zip")
You should get a result similar to this:
zip
"C:\\Rtools\\R-3.1\\bin\\zip.exe"
In other words, R should recognize the installation path.
On previous occasions when people told me this didn’t work, it was always because they thought they had a zip in the path, but it turned out they didn’t.
One last comment: installing 7zip may not work. The reason is that 7zip contains a utility called 7zip, but R will only look for a utility called zip.
I saw this link earlier but the additional clarification which made my code not work was
1. Address and Path of Rtools was not as straigt forward
2. You need to Reboot R
With regards to the address - always look where it was installed . I also used this code to set the path and ALWAYS ADD ZIP at the end
##Rtools.bin="C:\\Users\\User_2\\R-Portable\\Rtools\\bin"
Rtools.bin="C:\\Rtools\\bin\\zip"
sys.path = Sys.getenv("PATH")
if (Sys.which("zip") == "" ) {
system(paste("setx PATH \"", Rtools.bin, ";", sys.path, "\"", sep = ""))
}
Sys.which("zip")
you should get a return of
" C:\\RTools|\bin\zip"
From looking at Andrie's comment here: https://github.com/RevolutionAnalytics/AzureML/commit/9cf2c5c59f1f82b874dc7fdb1f9439b11ab60f40
Implies we can just download RTools and be done with it.
Download RTools from:
https://cran.r-project.org/bin/windows/Rtools/
During installation select the check box to modify the PATH
At first it didn't work. I then tried R32bit, and that seemed to work. Then R64 bit started working again. Honestly, not sure if I did something in the middle to make it work. Only takes a few minutes so worth a punt.
Try the following
-Download the Rtools file which usually contains the zip utility.
-Copy all the files in the "bin" folder of "Rtools"
-Paste them in "~/RStudio/bin/x64" folder
I would like to use the zip(utils) function, unzip function works fine, however, call zip e.g. zip ("out", "file.txt") does not return the file ("out.zip") to the working directory and R does not return any message at all - any error message and no massage about successful compression - if compression is successful R returns info such as "deflate - 40%." I checked various R versions and files - zip still doesn't work. On another computers, everything works fine. I have Windows XP. Furthermore, when I type the wrong name of the zip file to compress e.g. zip("out", "this_file_doesnt_exist.txt") R does not return any error at all ! I don't know much about computers, what should I check ? what could be problem in my case ? I turned off antivirus that didn't help.
You can use gzip from the package R.utils
library(R.utils)
df <- data.frame(x=10)
write.csv(df, file="x1.csv")
gzip("x1.csv")
> dir()
[1] "x1.csv.gz"
For those reading this on 2020:
Install Rtools (https://cran.r-project.org/bin/windows/Rtools/) and follow the documentation steps.
Then Zip command will wokr on Windows 10 machines.
For Windows 10 Users: While the abovementioned Rtools approach did not work for me in the context of zip() {utils}, package {zip} (package description) works fine without installing Rtools and without the need to change your existing code (as the {zip} package masks the functions zip() and unzip() of {utils}).