ManuelHentschel / VSCode-R-Debugger

R Debugger Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=RDebugger.r-debugger
MIT License
170 stars 11 forks source link

Use a script to install vscDebugger #109

Closed renkun-ken closed 4 years ago

renkun-ken commented 4 years ago

Closes #108

This PR switches to R/install.R for the installation of vscDebugger. It makes improvements in the following aspects:

ManuelHentschel commented 4 years ago

Thanks!

Now that we are using an extra script anyways, would it make sense to install vscDebugger first and determine its dependencies programmatically? Or would that risk additional problems/introduce unnecessary complexity?

installed.packages()['vscDebugger','Imports']
[1] "jsonlite(>= 1.6.0), R6"

(I'm not sure if the version of jsonlite is actually relevant)

renkun-ken commented 4 years ago

If we use remotes::install_url() then it could resolve the dependencies, which is the standard practice. I thought you were doing the manual installation of jsonlite and R6 on purpose to avoid any other dependencies when installing the package.

ManuelHentschel commented 4 years ago

I didn't use remotes before, because I wanted to keep the footprint of the debugger small and not install packages, that aren't used later. But I guess that factor can be safely ignored, since remotes is rather small and most people have it installed anyways...

ManuelHentschel commented 4 years ago

When trying to use the new update/install command, I get the following error:

D:\Documents\Projekte\vscode\RTools\vscode-R-debugger>"C:\Program Files\R\R-4.0.3\bin\x64\R.exe" --no-restore --quiet -f "c:\Users\Manuel\.vscode-insiders\extensions\rdebugger.r-debugger-0.4.2\R\install.R" --args "https://github.com/ManuelHentschel/VSCode-R-Debugger/releases/download/v0.4.2/vscDebugger_0.4.2.zip"
> repos <- getOption("repos")
> if (is.null(repos) || identical(repos, c(CRAN = "@CRAN@"))) {
+   options(repos = c(CRAN = "https://cloud.r-project.org/"))
+ }
>
> url <- commandArgs(trailingOnly = TRUE)[[1]]
> install.packages("remotes")
Installing package into 'D:/Documents/R/win-library/4.0'
(as 'lib' is unspecified)
trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.0/remotes_2.2.0.zip'
Content type 'application/zip' length 388314 bytes (379 KB)
==================================================
downloaded 379 KB

package 'remotes' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\Manuel\AppData\Local\Temp\RtmpugSqEw\downloaded_packages
> remotes::install_url(url, dependencies = TRUE)
Downloading package from url: https://github.com/ManuelHentschel/VSCode-R-Debugger/releases/download/v0.4.2/vscDebugger_0.4.2.zip

v  checking for file 'C:\Users\Manuel\AppData\Local\Temp\RtmpugSqEw\remotes43d8345379c\vscDebugger/DESCRIPTION'
-  preparing 'vscDebugger':
v  checking DESCRIPTION meta-information ...
   Warning in file(con, "r") :
     cannot open file 'man': No such file or directory
    ERROR
   computing Rd index failed:cannot open the connection
Error: Failed to install 'unknown package' from URL:
  System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr:
E> * checking for file 'C:\Users\Manuel\AppData\Local\Temp\RtmpugSqEw\remotes43d8345379c\vscDebugger/DESCRIPTION' ... OK
E> * preparing 'vscDebugger':
E> * checking DESCRIPTION meta-information ... OK
E> Warning in file(con, "r") :
E>   cannot open file 'man': No such file or directory
E>  ERROR
E> computing Rd index failed:cannot open the connection
Execution halted

Downloading the zip file and installing it directly with R CMD INSTALL vscDebugger_0.4.2.zip works fine though. I tried setting build=FALSE in the install_url call, but that does not work either.

Any ideas what might be causing this?

renkun-ken commented 4 years ago

I tried installing from the zip and the problem also occurs on Ubuntu:

> remotes::install_url(url, dependencies = TRUE)                                                                                                                                                                                                                             
Downloading package from url: https://github.com/ManuelHentschel/VSCode-R-Debugger/releases/download/v0.4.2/vscDebugger_0.4.2.zip
✔  checking for file ‘/tmp/RtmpDJd8Jk/remotes1c0ee5a76acb3/vscDebugger/DESCRIPTION’ ...
─  preparing ‘vscDebugger’:
✔  checking DESCRIPTION meta-information
   Warning in file(con, "r") :
     cannot open file 'man': No such file or directory
    ERROR
   computing Rd index failed:cannot open the connection
Error: Failed to install 'unknown package' from URL:
  System command 'R' failed, exit status: 1, stdout + stderr:
E> * checking for file ‘/tmp/RtmpDJd8Jk/remotes1c0ee5a76acb3/vscDebugger/DESCRIPTION’ ... OK
E> * preparing ‘vscDebugger’:
E> * checking DESCRIPTION meta-information ... OK
E> Warning in file(con, "r") :
E>   cannot open file 'man': No such file or directory
E>  ERROR
E> computing Rd index failed:cannot open the connection
Backtrace:
1: stop(remote_install_error(remotes[[i]], e))
2: value[[3L]](cond)
3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
4: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(res[[i]] <- install_remote(remotes[[i]], ...), error = function(e) {
6: install_remotes(remotes, dependencies = dependencies, upgrade = upgrade, 
7: remotes::install_url(url, dependencies = TRUE)

Looks like the zip file is too big to download and could easily fail.

> download.file(url, file)                                                                                                                                                                                                                                                   
trying URL 'https://github.com/ManuelHentschel/VSCode-R-Debugger/releases/download/v0.4.2/vscDebugger_0.4.2.zip'
Content type 'application/octet-stream' length 501258 bytes (489 KB)
================================================
downloaded 475 KB

Error in download.file(url, file) : 
  download from 'https://github.com/ManuelHentschel/VSCode-R-Debugger/releases/download/v0.4.2/vscDebugger_0.4.2.zip' failed
In addition: Warning messages:
1: In download.file(url, file) :
  downloaded length 486985 != reported length 501258
2: In download.file(url, file) :
  URL 'https://github-production-release-asset-2e65be.s3.amazonaws.com/259474247/38eb3680-2a63-11eb-9ad4-b6bf0d0c03fd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201120%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201120T080407Z&X-Amz-Expires=300&X-Amz-Signature=37dd11ec593b510a2898467963581e61f5435013b6bcaa5d07f628c712dbba51&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=259474247&response-content-disposition=attachment%3B%20filename%3DvscDebugger_0.4.2.zip&response-content-type=application%2Foctet-stream': Timeout of 60 seconds was reached
Backtrace:
1: download.file(url, file)

Manually download and file and use remotes::install_local(file) and it works. Then the error should be caused by trying to install a partially downloaded zip I guess?

ManuelHentschel commented 4 years ago

Manually download and file and use remotes::install_local(file) and it works.

That doesn't work on my system either:

> remotes::install_local('vscDebugger_0.4.2.zip')
Installing package into 'D:/Documents/R/win-library/4.0'
(as 'lib' is unspecified)
* installing *binary* package 'vscDebugger' ...
cp: unknown option -- )
Try '/usr/bin/cp --help' for more information.
ERROR: installing binary package failed
* removing 'D:/Documents/R/win-library/4.0/vscDebugger'
Error: Failed to install 'vscDebugger' from local:
  (converted from warning) installation of package 'C:/Users/Manuel/AppData/Local/Temp/Rtmp61TALv/remotes3de45b16211e/vscDebugger' had non-zero exit status
>

I'm a bit surprised by the part cp: unknown option -- ), since I'm on windows. Some version of cp seems to be installed, but I hav eno idea where that came from (wsl? git bash?) Edit: cp seems to be from Rtools: C:\rtools40\usr\bin\cp.exe

renkun-ken commented 4 years ago

And you install.packages("vscDebugger_0.4.2.zip") or R CMD INSTALL vscDebugger_0.4.2.zip and it works with the same file?

ManuelHentschel commented 4 years ago

Both work (identical file):

D:\Documents\Projekte\vscode\RTools\RDebuggerReleases\v0.4.2>R --silent
> install.packages('vscDebugger_0.4.2.zip')
Installing package into 'D:/Documents/R/win-library/4.0'
(as 'lib' is unspecified)
inferring 'repos = NULL' from 'pkgs'
package 'vscDebugger' successfully unpacked and MD5 sums checked
> q()

D:\Documents\Projekte\vscode\RTools\RDebuggerReleases\v0.4.2>R CMD INSTALL vscDebugger_0.4.2.zip
* installing to library 'D:/Documents/R/win-library/4.0'
package 'vscDebugger' successfully unpacked and MD5 sums checked
renkun-ken commented 4 years ago

Sorry that was a mistake, cannot install binary package built from Windows on Linux:

> remotes::install_local(file, dependencies = TRUE)                                                                                                                                                                                                                          
Installing package into '/home/renkun/R/x86_64-pc-linux-gnu-library/4.0'
(as 'lib' is unspecified)
* installing *binary* package 'vscDebugger' ...
* DONE (vscDebugger)

> library(vscDebugger)                                                                                                                                                                                                                                                       
Error: package or namespace load failed for 'vscDebugger' in library.dynam(lib, package, package.lib):
 shared object 'vscDebugger.so' not found
Backtrace:
1: stop(msg, call. = FALSE, domain = NA)
2: value[[3L]](cond)
3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
4: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch({
6: library(vscDebugger)
renkun-ken commented 4 years ago

I could reproduce the error on a Windows 10 VM:

Installing package into 'C:/Users/renku/Documents/R/win-library/3.6'
(as 'lib' is unspecified)
* installing *binary* package 'vscDebugger' ...
cp: unknown option -- )
Try '/Rtools/bin/cp --help' for more information.
ERROR: installing binary package failed
* removing 'C:/Users/renku/Documents/R/win-library/3.6/vscDebugger'
Error: Failed to install 'vscDebugger' from local:
  (converted from warning) installation of package 'C:/Users/renku/AppData/Local/Temp/RtmpyUOq4R/remotes183c35025c6/vscDebugger' had non-zero exit status

Looks similar with https://github.com/r-lib/remotes/issues/456.

renkun-ken commented 4 years ago

I revert to using install.packages() for now.

The order of install.packages() matters on Linux and macOS. If the dependencies are missing, then install.packages(file, repos=NULL) will fail. But the same does not seem true on Windows?

ManuelHentschel commented 4 years ago

Apparently R on windows lets you install and even use packages with missing dependencies, it just warns you about them:

> vscDebugger::.vsc.print(1)
Warning: namespace 'R6' is not available and has been replaced
by .GlobalEnv when processing object '<unknown>'
ManuelHentschel commented 4 years ago

The current version seems to be working fine, so I'd merge this now and we can reopen the issue when/if the related issues in remotes are somehow resolved, ok?

renkun-ken commented 4 years ago

LGTM