Why is blogdown putting a mamba command through normalizePath? - r

Here's what I'm doing:
I have a blog that uses blogdown to render .Rmd files.
Some of the code snippets in the blog are in Python. I'm using reticulate for that.
I'm using a GitHub workflow to build and publish the blog as part of a larger website. This workflow sets up the environment and package dependencies in miniconda.
The last time this ran was six months ago. At that time, it worked. Now, it does not. I can't seem to replicate the behavior locally for more detailed debugging.
It seems to be trying to put a mamba command into normalizePath instead of a filesystem path (www-main is the name of the repository):
conda activate www-main
Rscript -e 'blogdown::build_site(local=FALSE, run_hugo=FALSE, build_rmd="content/blog/2020-08-28-api.Rmd")'
shell: /usr/bin/bash -l {0}
env:
CONDA_PKGS_DIR: /home/runner/conda_pkgs_dir
Rendering content/blog/2020-08-28-api.Rmd...
[...]
Quitting from lines 401-410 (2020-08-28-api.Rmd)
Error in normalizePath(conda, winslash = "/", mustWork = TRUE) :
path[1]="# cmd: /usr/share/miniconda/condabin/mamba update --name www-main --file /home/runner/work/www-main/www-main/conda": No such file or directory
Calls: local ... python_munge_path -> get_python_conda_info -> normalizePath
Execution halted
Error: Failed to render content/blog/2020-08-28-api.Rmd
Execution halted
Lines 401-410 of 2020-08-28-api.Rmd are a Python code block:
400 ```{python python-data, dev='svg'}
401 import covidcast
402 from datetime import date
403 import matplotlib.pyplot as plt
404
405 data = covidcast.signal("fb-survey", "smoothed_hh_cmnty_cli",
406 date(2020, 9, 8), date(2020, 9, 8),
407 geo_type="state")
408 covidcast.plot_choropleth(data, figsize=(7, 5))
409 plt.title("% who know someone who is sick, Sept 8, 2020")
410 ```
The useful bits of the output of conda info, in case it helps:
active environment : www-main
active env location : /usr/share/miniconda/envs/www-main
shell level : 1
user config file : /home/runner/.condarc
populated config files : /home/runner/.condarc
conda version : 4.12.0
conda-build version : not installed
python version : 3.9.12.final.0
virtual packages : __linux=5.15.0=0
__glibc=2.31=0
__unix=0=0
__archspec=1=x86_64
base environment : /usr/share/miniconda (writable)
conda av data dir : /usr/share/miniconda/etc/conda
conda av metadata url : None
channel URLs : https://conda.anaconda.org/conda-forge/linux-64
https://conda.anaconda.org/conda-forge/noarch
https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /home/runner/conda_pkgs_dir
envs directories : /usr/share/miniconda/envs
/home/runner/.conda/envs
platform : linux-64
user-agent : conda/4.12.0 requests/2.27.1 CPython/3.9.12 Linux/5.15.0-1020-azure ubuntu/20.04.5 glibc/2.31
UID:GID : 1001:121
netrc file : None
offline mode : False
I found this, but their workaround doesn't make sense for me since I'm not using papermill: https://github.com/rstudio/reticulate/issues/1184
I found this, but my paths don't have spaces: https://github.com/rstudio/reticulate/issues/1149
I found this, but their problem includes an entirely reasonable value for path[1], unlike mine: How can I tell R where the conda environment is via a docker image?
The build environment for this is a bit of a bear but I can probably put together a minimum working (/nonworking) example if needed, lmk

I tracked this down to at least two bits of weird/buggy behavior in reticulate and found a workaround: switch from vanilla miniconda to Mambaforge.
The TL;DR seems to be that whatever wacky ubuntu-latest setup-miniconda#v2 environment started putting into meta/history doesn't include a create line, which is what reticulate needs in order to figure out which conda goes with which python, because (1) it ignores the reticulate.conda_binary setting for some reason, and (2) it uses a more restrictive regex to parse the lines of the history file than the regex it uses to select them. Mambaforge does include the create line, so reticulate is happy.
- uses: conda-incubator/setup-miniconda#v2
with:
python-version: 3.9
activate-environment: www-main
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
use-only-tar-bz2: true # (for caching support)
- name: Update environment
run: mamba env update -n www-main -f environment.yml

Related

Installing from Archive of Formal Proofs

I'm trying to install Grothendieck_Schemes from
https://www.isa-afp.org/entries/Grothendieck_Schemes.html#
I downloaded the tar and uncompressed it. The contents are
$ ls -l
Comm_Ring.thy
Group_Extras.thy
ROOT
Scheme.thy
Set_Extras.thy
Topological_Space.thy
document/
root.bib
root.tex
Then I run
$ isabelle components -u ./Downloads/Grothendieck_Schemes/
Added component "/home/username/Downloads/Grothendieck_Schemes"
but when I start Isabelle I get error
C:\Users\Aleksander\.isabelle\Isabelle2022\jedit\jars\isabelle_jedit_main.jar:
Cannot start:
*** Bad imports session "Jacobson_Basic_Algebra" for "Grothendieck_Schemes" (line 3 of "/home/username/Downloads/Grothendieck_Schemes/ROOT")
So I suppose I should install the dependency "Jacobson_Basic_Algebra"? But there is no such package on AFP. I'm thinking that maybe I should have removed the ROOT file. It's contents are
chapter AFP
session "Grothendieck_Schemes" (AFP) = HOL +
options [timeout = 600]
sessions
"Jacobson_Basic_Algebra"
theories
Scheme
document_files
"root.tex"
"root.bib"
I tried running this instead but it fails
$ isabelle components -u ./Downloads/Grothendieck_Schemes/*.thy
*** Bad component directory: "/home/username/Downloads/Grothendieck_Schemes/Comm_Ring.thy"
How do I install these packages properly?

Trouble running whitebox in Rstudio ("~/whitebox_tools.exe" not found)

I am trying to run 'whitebox' packages in R.
To get started, I follow the steps in the link: https://github.com/giswqs/whiteboxR
install.packages("whitebox")
whitebox::install_whitebox()
Console:
------------------------------------------------------------------------
Could not find WhiteboxTools!
------------------------------------------------------------------------
Your next step is to download and install the WhiteboxTools binary:
> whitebox::install_whitebox()
If you have WhiteboxTools installed already run `wbt_init(exe_path=...)`':
> wbt_init(exe_path='/home/user/path/to/whitebox_tools')
For whitebox package documentation, ask for help:
> ??whitebox
For more information visit https://giswqs.github.io/whiteboxR/
------------------------------------------------------------------------
Performing one-time download of WhiteboxTools binary from
https://www.whiteboxgeo.com/WBT_Windows/WhiteboxTools_win_amd64.zip
(This could take a few minutes, please be patient...)
trying URL 'https://www.whiteboxgeo.com/WBT_Windows/WhiteboxTools_win_amd64.zip'
Content type 'application/zip' length 15383844 bytes (14.7 MB)
downloaded 14.7 MB
WhiteboxTools binary is located here: C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe
You can now start using whitebox
library(whitebox)
wbt_version()
After downloading i run:
library(whitebox)
if(wbt_init()==TRUE){print("all good")}#confirms if the whitebox_tools.exe exists in,'C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe'.
console:
[1] "all good"
Now, if I try to run any function in the whitebox package, it returns an odd error message
for example
wbt_version()
returns:
Error :
Error running WhiteboxTools
whitebox.exe_path: "C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe"; File exists? TRUE
Arguments: --version
Error in system(exeargs, intern = TRUE, ignore.stderr = ignore.stderr, : '"C:/Users/frsu0056/OneDrive - Umeå universitet/Documents/R/win-library/4.1/whitebox/WBT/whitebox_tools.exe"' not found
Yet, the wbt_init() returns TRUE so the file exists in the given directory. Nevertheless, the wbt_version() function can not find it.
And so the story goes for any function in the whitebox package. It just can't find the .exe file yet the file exists in the folder where it is supposed to be.
Anyone else get the same problem running this? And what could possibly be wrong here?
Below is the .exe file resting in the directory.
The problem with whitebox in my experience is that it cannot decode spaces. I don't think the problem is the one drive folder per se, just that there are spaces in the file path. I would suggest not having your packages installed in a one drive folder or any other folder where the path has spaces. To change the folder where your libraries are installed, refer to the solution: Change R default library path using .libPaths in Rprofile.site fails to work

Error installing miniconda on GitHub Actions in an R project

I am trying to build and deploy this bookdown project with GitHub Actions. One of the chapters uses the keras R package, which means I need to install Conda (or set up a virtual environment). At the end of the Miniconda installation command, there is an error when trying to collect metadata.
2020-06-24T04:47:59.7495480Z * Miniconda has been successfully installed at '/Users/runner/Library/r-miniconda'.
2020-06-24T04:47:59.7496060Z [1] "/Users/runner/Library/r-miniconda"
2020-06-24T04:48:00.3909040Z * Project '~/runners/2.263.0/work/drake/drake' loaded. [renv 0.10.0]
2020-06-24T04:48:00.7964920Z * The project and lockfile are out of sync -- use `renv::status()` for more details.
2020-06-24T04:48:00.7968340Z Warning message:
2020-06-24T04:48:00.7969190Z Project requested R version '3.6.0' but '4.0.1' is currently being used
2020-06-24T04:48:05.2408080Z Collecting package metadata (current_repodata.json): ...working... failed
2020-06-24T04:48:05.2410390Z
2020-06-24T04:48:05.2410820Z NotWritableError: The current user does not have write permissions to a required path.
2020-06-24T04:48:05.2411080Z path: /usr/local/miniconda/pkgs/cache/b89cf7bf.json
2020-06-24T04:48:05.2411230Z uid: 501
2020-06-24T04:48:05.2411350Z gid: 20
2020-06-24T04:48:05.2411430Z
2020-06-24T04:48:05.2411690Z If you feel that permissions on this path are set incorrectly, you can manually
2020-06-24T04:48:05.2411940Z change them by executing
2020-06-24T04:48:05.2412010Z
2020-06-24T04:48:05.2412260Z $ sudo chown 501:20 /usr/local/miniconda/pkgs/cache/b89cf7bf.json
2020-06-24T04:48:05.2412330Z
2020-06-24T04:48:05.2413470Z In general, it's not advisable to use 'sudo conda'.
2020-06-24T04:48:05.2413570Z
2020-06-24T04:48:05.2414250Z
2020-06-24T04:48:05.2886400Z ##[error]Error: Error 1 occurred creating conda environment r-reticulate
2020-06-24T04:48:05.2890770Z Execution halted
2020-06-24T04:48:05.3050700Z ##[error]Process completed with exit code 1.
The full job log is here.
Depending on how R is set up, this post might be helpful for you. You might need to configure the .Renviron file.
Unable to change python path in reticulate (R)

Nbgrader with Littlest JupyterHub releases assignment to course directory but not to /srv/nbgrader/exchange

Operating system
nbgrader --version: 0.6.1
jupyterhub --version (if used with JupyterHub): 1.0.0 (Using littlest Jupterhub)
jupyter notebook --version
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.7.2
ipython : 7.13.0
ipykernel : 5.2.0
jupyter client : 6.1.2
jupyter lab : 1.2.8
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.4
traitlets : 4.3.3
Expected behavior: When used
nbgrader release_assignment ps1 --force --debug
It should release the assignment in /srv/nbgrader/exchange shared folder.
Actual behavior
I am facing an issue when I try to release the assignment:
nbgrader release_assignment ps1 --force --debug
It releases the assignment without errors but to the location (/home/jupyter-tljh-admin/course_id/outbound/ps1) but not to the shared location /srv/nbgrader/exchange:
[ReleaseAssignmentApp | INFO] Overwriting files: /home/jupyter-tljh-admin/course_id ps1
[ReleaseAssignmentApp | INFO] Source: /home/jupyter-tljh-admin/course_id/release/./ps1
[ReleaseAssignmentApp | INFO] Destination: /home/jupyter-tljh-admin/course_id/outbound/ps1
[ReleaseAssignmentApp | INFO] Released as: /home/jupyter-tljh-admin/course_id ps1
The folder /srv/nbgrader/exchange has write permissions.
Please suggest, what could be the issue?
I faced a similar problem. When I opened the Formgrader there was a notification saying that the directory /srv/nbgrader/exchange does not exist or could not be created. I simply created the directory on my own, but not directly. First I created the directory /srv/nbgrader with sudo. Then I cd into that directory and created the subdirectory exchange, also with sudo. I also added a nbgrader_config.py in /etc/jupyter with the following content:
from nbgrader.auth import JupyterHubAuthPlugin
c = get_config()
c.Exchange.path_includes_course = True
c.Authenticator.plugin_class = JupyterHubAuthPlugin
This solved the issue for me.
Create the /srv/nbgrader/exchange directory and add the permissions like this: chmod ugo+rw /srv/nbgrader/exchange
Open the nbgrader_config.py that was created after running nbgrader quickstart <course-id>
Make sure these two lines are present and uncommented:
c.CourseDirectory.course_id = "<course-id>"
c.IncludeHeaderFooter.header = "source/header.ipynb"
Search for the specific line that says: c.CourseDirectory.root = '', uncomment it, and set it to c.CourseDirectory.root = /full/path/to/your/course-id/
Search for the specific line that says: c.Exchange.assignment_dir = '.' and actually set it to c.Exchange.assignment_dir = '/srv/nbgrader/exchange'
Copy this exact nbgrader_config.py into .jupyter or any other directory that apprear in jupyter --paths
Stop and restart your server

Error while building ggplot2 book : could not find function "pandoc_latex_engine_args"

I just reported the following issue to the hadley/ggplot2-book repository:
When i press STRG+SHIFT+B in RStudio to build the book as described in the Readme I get this error:
mkdir -p book/tex
mkdir -p book/tex/_figures
mkdir -p book/tex/diagrams
cp book/ggplot2-book.tex book/tex/ggplot2-book.tex
Rscript book/render-tex.R data-manip.rmd
Error in rmarkdown::pandoc_options(to = "latex", from = "markdown_style", :
could not find function "pandoc_latex_engine_args"
Calls: <Anonymous> -> <Anonymous> -> structure -> <Anonymous>...
I have R 3.2.2, Rtools 3,2,x , pandoc 1.15.2 and installed all the dependencies as well as the inconsolata font. I have MikTeX 2.9 and also updated all packages that where updatable.
When I try ?pandoc_latex_engine_args (which presumably causes the error) the help page opens so this function should be available to R. I tried on 2 different computers (Windows 10 and Windows 7) and reran the complete installation process on each without any change. I also tried to manually build the book using the Cygwin terminal but this gives the same error.
Has anyone trying to build the book had the same problem or even better: does anyone know how to fix this?

Resources