OpenCPU cannot load Namespace 400 (Bad Request) Error in server mode - r

I've written a OpenCPU app package and have successfully tested it in single server mode. The server is setup and it can find the app no problem.
But it's erroring out on some of the ocpu calls with the following (from Chrome JS console):
POST http://mydomain/ocpu/library/userengagementdashboard/R/metricsList 400 (Bad Request) jquery-1.10.2.min.js:6
OpenCPU error HTTP 400
package or namespace load failed for 'userengagementdashboard'
In call:
NULL
Didn't get these errors in the single user server mode.
If I check on http://mydomain/ocpu/library/userengagementdashboard/NAMESPACE I get:
export(aggregatePlot)
export(clusterFun)
export(facetPlot)
export(facetsList)
export(getDataAll)
export(getDataFacet)
export(getDataTime)
export(getDataTimeFacet)
export(mergeClusters)
export(metricsList)
export(timeFacetPlot)
export(timePlot)
import(RDruid)
import(ggplot2)
import(lubridate)
import(parallel)
import(plyr)
import(reshape)
Is there a problem with my imports maybe?
UPDATE:
Solved this thanks to Jeroen's suggestion that I perhaps didn't have all the dependencies.
First I looked at the dependencies under http://mydomain/ocpu/library/ and installed any missing packages to the correct library location.
Then some of the imports and dependencies of these dependent packages had not been installed so I installed their dependencies as well. Problem solved!

Your package probably fails to load because some dependencies are not installed. This problem usually appears if the NAMESPACE file imports dependencies, which are not declared in the DESCRIPTION file. So if your NAMESPACE contains:
import(RDruid)
import(ggplot2)
import(lubridate)
import(parallel)
import(plyr)
import(reshape)
than your DESCRIPTION needs to contain a line:
Imports: Druid, ggplot2, lubridate, parallel, plyr, reshape
The R package manager looks at the DESCRIPTION to install dependencies when installing your package.

Related

Including any package function call in the project .Rprofile of {renv} projects breaks GitHub Actions

The whole issue is stated in the title.
Try it by yourself:
create a project w/ {renv},
install a package, and add any function call from that package in the project .Rprofile,
snapshot it to renv.lock,
put a GitHub action (e.g., using {usethis} wrapper),
push it on GitHub.
You can find a ready-to-inspect errored reprex project here.
I have tried to:
install the package from within the project .Rprofile
before or after sourcing renv/activate.R
using renv::install or utils::install.packages (setting an option for the CRAN repo)
using utils::install.packages, sourcing renv/activate.R, and next using renv::install
None of my options/combinations worked, and the GH-action still return the error: "Error: Error in loadNamespace(x) : there is no package called ‘<package-name>’".
Do you have some hints for trying to solve this issue? Is that an issue from {renv} or GH-action?
Thank you!
Corrado.

Why is R library not loading in app.powerbi.com?

I keep getting the following error on app.powerbi.com:
"Error in pivot_wider(data, names_from=names,values_from=values): could not find function "pivot_wider""
I load the 'tidyr' package as a required library.
I get the same error when using "spread" instead of pivot_wider.
When I specify the function using:
tidyr::pivot_wider(data, names_from=names, values_from=values)
I get a different error:
"Error in loadNamespace(name): there is no package called 'tidyr'".
PowerBI Desktop everything works perfectly fine. It's only on the published PowerBI report that I get the error.
What can I do to resolve this issue?
Alternative library / function to 'pivot_wider' or 'spread'?
I was able to verify using print statements that the report on powerbi.com was not able to access the r packages that were installed.
I was using a .libPaths()[3] to point to the location where my libraries were installed, but this didn't work in powerbi.com.
I ended up re-installing R to a location where I could install packages to, since admin rights are necessary to write to the C:/users/program files location.

Installing a package from private GitLab server on Windows

I am struggling with installing a package from a GitLab repository on a Windows computer.
I found different hints but still have problems to install my package from GitLab. First of all, I generated a public and private key with puttygen.exe. The files need to be changed afterwards, I had to remove comments and stuff so they look like my the file on my Unix system. So now, both public and private key files have just a single line.
I tried to install my package via devtools::install_git which takes very long and I get the error message
Error: Failed to install 'unknown package' from Git:
Error in 'git2r_remote_ls': Failed to authenticate SSH session: Unable to send userauth-publickey request
And with devtools::install_gitlab I get a different error message and I somehow have the feeling, the link which gets generated doesn't fit to my GitLab server.
Error: Failed to install 'unknown package' from GitLab:
cannot open URL 'https://gitlab.rlp.net/api/v4/projects/madejung%2FMQqueue.git/repository/files/DESCRIPTION/raw?ref=master'
My complete code to test at the moment is
creds <- git2r::cred_ssh_key(publickey="~/.ssh/id_rsa_gitlab.pub",
privatekey="~/.ssh/id_rsa_gitlab")
devtools::install_git(
url='git#gitlab.rlp.net:madejung/MQqueue.git',
quiet=FALSE,
credentials=creds)
devtools::install_gitlab(
repo='madejung/MQqueue.git',
host='gitlab.rlp.net',
quiet=FALSE,
credentials=creds
)
My id_rsa_gitlab.pub file looks like this and is just a single line:
ssh-rsa AAAA....fiwbw== rsa-key-20200121
The id_rsa_gitlab file has just the code:
AAABA.....3WNSIAGE=
Update
On my Mac system it works as expected after installing the libssh2 library via homebrew and and recompiling git2r with install.packages("git2r", type = "source").
So the working code on my machine is:
creds <- git2r::cred_ssh_key(publickey="~/.ssh/id_rsa_gitlab.rlp.net.pub",
privatekey="~/.ssh/id_rsa_gitlab.rlp.net")
devtools::install_git(
url='git#gitlab.rlp.net:madejung/MQqueue.git',
quiet=FALSE,
credentials=creds
)
For some strange reason, the devtools::install_git call needs about a minute to fail in the end. I have no idea where the problem here is.
After struggling for almost a day, I found a solution I can live with...
I first created a PAT (Personal Access Token) in my gitlab account and granted full API access. For some reason the read_only access didn't worked and I am now tired to figure out what the problem is.
After this I had still problems to install my package and for some reason, the wininet setting for downloading doesn't work.
I used the command capabilities("libcurl") to check if libcurl is available on my windows, which was and tried to overwrite wininet to libcurl by using method='libcurl' in the install function. Somehow, this was not enough so I overwrote the options variable download.file.method directly.
options("download.file.method"='libcurl')
devtools::install_gitlab(
repo='madejung/MQqueue',
auth_token='Ho...SOMETHING...xugzb',
host='gitlab.rlp.net',
quiet=FALSE, force=TRUE
)

install.keras() in RStudio fails with http connection error

I've been trying to install and run keras in RStudio (Windows) in vain.
i installed keras package using normal package "keras"
(didn't use github)
I've installed latest python (3.6) and Anaconda.
then i use
> library(keras)
> install.keras()
and i get this error:
Creating r-tensorflow conda environment for TensorFlow installation...
Fetching package metadata ... CondaHTTPError: HTTP 000 CONNECTION
FAILED for url
https://repo.continuum.io/pkgs/main/win-64/repodata.json.bz2
Elapsed: -
An HTTP error occurred when trying to retrieve this URL. HTTP errors
are often intermittent, and a simple retry will get you on your way.
ConnectTimeout(MaxRetryError("HTTPSConnectionPool(host='repo.continuum.io',
port=443): Max retries exceeded with url:
/pkgs/main/win-64/repodata.json.bz2 (Caused by
ConnectTimeoutError(, 'Connection to repo.continuum.io timed out.
(connect timeout=9.15)'))",),)
Error: Error 1 occurred creating conda environment r-tensorflow In
addition: Warning message: running command
'"C:\PROGRA~3\ANACON~1\Scripts\conda.exe" "create" "--yes" "--name"
"r-tensorflow" "python=3.6"' had status 1
I've looked up everywhere on the web and can't figure out how to install keras and tensorflow properly. Using latest version of R (3.4.2)
Every method fails somewhere.
just to add to misery, i've also tried:
> devtools::install_github("rstudio/keras")
and i get this error:
Installation failed: Timeout was reached: Connection timed out after
10015 milliseconds
I am not behind any authenticated proxies. So, after multiple failure, i just downloaded the zip file from github and manually installed it using the zip file.
i also tried install.packages("keras") and that didn't give me any error either.
when i call the library i don't get any errors (as shown above)
UPDATE: I was able to install and use the package very easily on another computer that doesn't have python/anaconda installed on it already.
UPDATE 2: my proxy does not need authentication and there is no https_proxy either.
OK,, FINALLY found a solution.
Turns out RStudio uses a lot of default proxy settings, so i needed to change all that and set up my own proxy settings.
First step:
Rstudio --> Tools --> Global Options --> packages --> uncheck both "Use secure download method for HTTP" and "Use Internet Explorer librayr/proxy for HTTP"
Second step, in RStudio type:
> file.edit('./.Renviron')
Either an empty file or some file with already existing proxy settings will open. (Mine was empty). Then I included the following two:
http_proxy=http://myusename:password#proxy.server.com:port/
https_proxy=http://myusename:password#proxy.server.com:port/
(a few notes: I didn't have a https_proxy setting but I still needed to use the http_proxy details for my https_proxy setting. This was one of the culprits for my issue. Also, I needed to include the username:password even though my proxy doesn't need secure authentication. Same thing goes with the port. Port number had to be included, otherwise it wouldn't work.
Step 3:
Saved the new changes in .Renviron file and restarted RStudio.
I checked my proxy settings in RStudio after restart by typing:
> Sys.getenv("http_proxy")
> Sys.getenv("https_proxy")
The first few times i did this i realised that the proxy settings were not being changed in RStudio because i was editing the wrong .Renviron file. So, it's best to use file.edit('~/.Renviron') in step 2 to make sure it's the right file.
After all this, when i ran install.keras(), it installed successfully, including installing Tensorflow. Again, initially i had skipped step 1 so keras started being installed but it failed at installing tensorflow.
It was only going through all the steps that i was able to install both keras and tensorflow successfully over a proxy. Hope this helps.
Uninstalling Anaconda3 and installing Anaconda2 (i.e. Python 2.7) did the trick for me: https://www.anaconda.com/download/

Run `devtools::document()` before installing

I've just pushed a package on Github, which I regularly document, test and install on my machine with the following R commands:
library(devtools)
library(testthat)
setwd("bimark")
document() # cheers to roxygen2!
use_testthat() # cheers to testthat!
setwd("..")
install("bimark", build_vignettes=TRUE) # cheers to R-markdown!
library(bimark)
test_package("bimark")
run_examples("bimark")
However, installing it from github with:
install_github("iago-lito/bimark")
does not work since
ERROR: a 'NAMESPACE' file is required
The reason why I do not version my NAMESPACE file is that it is automatically generated by devtools::document().
How can I make the full doc-test-installation easy for my users without versionning non-source files such as NAMESPACE?
NAMESPACE is autogenerated only if devtools::document() and roxygen2 is used. Otherwise, you create it by hand. Therefore, I think they consider it as a source file which needs to be versioned.

Resources