Repository: carpentriesoffline/offlinedatasci (language: python)

Issue:
offlinedatasci install minicran not working
Trying to install just minicran causes error  saying there is no package called miniCRAN
- using R 4.3.2
- using python 3.10.4
Check if repos is null for R and set to cloud if needed



Discussion / hints:
Can you post the full error message. We explicitly install it prior to using it so presumably there's an earlier failure. Also, what's the OS?
This is on Windows 10:

```
offlinedatasci install minicran /install/path                              
Loading required package: miniCRAN                                                                                      
Warning message:                                                                                                        
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :                                   
  there is no package called 'miniCRAN'                                                                                 
Loading required package: remotes                                                                                       
Error: Failed to install 'miniCRAN' from GitHub:                                                                          
  Timeout was reached: [api.github.com] SSL/TLS connection timeout                                                      
Execution halted
```
Tried again after installing R 4.4.0. This time I get

```
Loading required package: miniCRAN                                                                                      
Warning message:                                                                                                        
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :                                  
  there is no package called 'miniCRAN'                                                                                 
Loading required package: remotes                                                                                       
Using GitHub PAT from the git credential store.                                                                         
Error: Failed to install 'unknown package' from GitHub:                                                                   
  cannot open URL 'https://api.github.com/repos/ethanwhite/miniCRAN/contents/DESCRIPTION?ref=HEAD'                      Execution halted  
```
OK, thanks. I think is all stemming from the fact that miniCRAN went through a long period of zero maintenance (requiring us to fork it) combined with some upstream changes. Fortunately minicran has finally been updated so let's switch back to installing from CRAN and see if that helps.
Getting this here, will try setting a mirror and see if it works after that

```
❯ offlinedatasci install minicran tmp
Loading required package: miniCRAN
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘miniCRAN’
Loading required package: remotes
Error in contrib.url(repos, "source") :
  trying to use CRAN without setting a mirror
Calls: install.packages -> contrib.url
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘remotes’
Execution halted
```
I just merged #122 which should fix this and also adds automated testing to catch this earlier next time. Re-install from the main branch (docs available in the README if you need them) and let me know if that fixes things.
If someone can confirm that this is fixed I'll roll a new release
Getting a slightly different error:

```
❯ offlinedatasci install r-packages tmp
Loading required package: miniCRAN
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘miniCRAN’
Error in contrib.url(repos, "source") :
  trying to use CRAN without setting a mirror
Calls: install.packages -> contrib.url
Execution halted
```
Thanks @abhidg. I assume the test is failing for you locally as well?
#127 will hopefully fix this new error. Still trying to figure out how to add a test for it, so would appreciate someone this is failing for checking if the fix works.


Fix patch:
diff --git a/.github/workflows/package-check.yml b/.github/workflows/package-check.yml
index a81914a..ee5c9a2 100644
--- a/.github/workflows/package-check.yml
+++ b/.github/workflows/package-check.yml
@@ -37,6 +37,9 @@ jobs:
           pip install --prefer-binary lxml
       - name: Install testing dependencies
         run: pip install pytest
+      - name: Set CRAN repository to @CRAN@ to test behavior on systems with no default repos
+        run: |
+          cp test/Rprofile.site ~/.Rprofile
       - name: Test package installation
         run: pip install .
       - name: Package tests
diff --git a/offlinedatasci/miniCran.R b/offlinedatasci/miniCran.R
index 0d6a13c..a619396 100644
--- a/offlinedatasci/miniCran.R
+++ b/offlinedatasci/miniCran.R
@@ -14,7 +14,7 @@ if (!require("miniCRAN")) {
 }
 
 if (install_minicran) {
-    if (is.null(getOption("repos"))){
+    if (!grepl("http", getOption("repos"))){
         #Lack of a default repo can cause the install to fail
         install.packages("miniCRAN", repos = "https://cloud.r-project.org" )
     } else {


Test patch:
diff --git a/test/Rprofile.site b/test/Rprofile.site
new file mode 100644
index 0000000..4047e12
--- /dev/null
+++ b/test/Rprofile.site
@@ -0,0 +1,1 @@
+options(repos = "@CRAN@")
\ No newline at end of file