Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move R code into hera #130

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open

move R code into hera #130

wants to merge 66 commits into from

Conversation

romainfrancois
Copy link
Contributor

This is early stage. Probably does not work yet. I'll keep going tomorrow.

This will be much cleaner because the way we structured the code previously in xeus-r was essentially mimicing what an R package does, but not as good.

@romainfrancois
Copy link
Contributor Author

Thanks @SylvainCorlay for the ☎️ hints, I'll resume later, but one thing we can do perhaps is to make the files with R CMD INSTALL --library=lib ../hera which makes all the files into the lib/hera directory, and then we can move that thing with cmake install() and/or do whatever is equivalent in EMSCRIPTEN:

(xeusr2025) romainfrancois@tada build % mkdir lib
(xeusr2025) romainfrancois@tada build % R CMD INSTALL --library=lib ../hera
* installing *source* package ‘hera’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (hera)
(xeusr2025) romainfrancois@tada build % tree lib/hera
lib/hera
├── DESCRIPTION
├── INDEX
├── LICENSE
├── Meta
│   ├── Rd.rds
│   ├── features.rds
│   ├── hsearch.rds
│   ├── links.rds
│   ├── nsInfo.rds
│   └── package.rds
├── NAMESPACE
├── R
│   ├── hera
│   ├── hera.rdb
│   └── hera.rdx
├── help
│   ├── AnIndex
│   ├── aliases.rds
│   ├── hera.rdb
│   ├── hera.rdx
│   └── paths.rds
└── html
    ├── 00Index.html
    └── R.css

5 directories, 20 files

@SylvainCorlay
Copy link
Member

R CMD INSTALL --library=lib ../hera which makes all the files into the lib/hera directory, and then we can move that thing with cmake install() and/or do whatever is equivalent in EMSCRIPTEN.

That's great. I think we should be able to get away with that without publishing hera until it fuly stabilises.

@romainfrancois romainfrancois marked this pull request as ready for review February 12, 2025 13:26
@romainfrancois
Copy link
Contributor Author

I've added R CI with a tweaked usethis::use_github_action() so that hera is checked as a normal R package independently, this will give us a place to add testing, checking various things etc ...

@romainfrancois
Copy link
Contributor Author

For me to be happy about merging, let me just check that the R functions that are currently called from the xeus-r internals are all correctly exported etc ... because before this used to rely on a pseudo 📦 structure that no longer is.

@romainfrancois
Copy link
Contributor Author

I think it's good for now. We'll probably need to export/document the classes in the comm.R file later, but this is a pretty big PR already. Will Follow up.

@IsabelParedes
Copy link
Member

Has it been verified that it works with JupyterLite? Or should I test it?

@SylvainCorlay
Copy link
Member

Has it been verified that it works with JupyterLite? Or should I test it?

I don't think it has.

Copy link
Member

@IsabelParedes IsabelParedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @romainfrancois ! I like where this is going, but to make it compatible with Emscripten we still need to make some changes.

In FindR.cmake

find_program(R_COMMAND R DOC "R executable.")
find_program(R_SCRIPT_COMMAND Rscript DOC "Rscript executable.")

These variables will point to the executables in the wasm environment, but we cannot execute them directly because they're JavaScript files. So we cannot use these to build hera.

When we cross-compile other R packages, we rely on cross-r-base. But this requires overwriting some files in PREFIX. I don't have a good solution yet, but I'll give it some more thought.

# ======================

message(STATUS "Installing R 📦 hera to ${R_HOME}/library")
execute_process(COMMAND ${R_COMMAND} CMD INSTALL --preclean --no-staged-install --build ../hera)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command should have failed for the Emscripten build

 -- Installing R 📦 hera to /home/runner/micromamba/envs/xeus-r-wasm-host/lib/R/library
/home/runner/micromamba/envs/xeus-r-wasm-host/lib/R/bin/R: line 279: /home/runner/micromamba/envs/xeus-r-wasm-host/lib/R/bin/exec/R: Permission denied
/home/runner/micromamba/envs/xeus-r-wasm-host/lib/R/bin/R: line 279: exec: /home/runner/micromamba/envs/xeus-r-wasm-host/lib/R/bin/exec/R: cannot execute: Permission denied
/home/runner/micromamba/envs/xeus-r-wasm-host/bin/Rscript: 1: //: Permission denied
/home/runner/micromamba/envs/xeus-r-wasm-host/bin/Rscript: 2: //: Permission denied
/home/runner/micromamba/envs/xeus-r-wasm-host/bin/Rscript: 3: //: Permission denied
/home/runner/micromamba/envs/xeus-r-wasm-host/bin/Rscript: 4: //: Permission denied
/home/runner/micromamba/envs/xeus-r-wasm-host/bin/Rscript: 5: Syntax error: "(" unexpected

Maybe we can add a result variable to make sure it fails when the command doesn't work

execute_process(COMMAND ${R_COMMAND} CMD INSTALL --preclean --no-staged-install --build ../hera
RESULT_VARIABLE result
)

if(NOT result EQUAL "0")
    message(FATAL_ERROR "Command failed with return code ${result}")
endif()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started some workarounds here https://github.com/IsabelParedes/xeus-r/tree/pr-hera

It builds hera for the wasm environment, but the internal packages in R base still need to be restored to their original state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants