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

I would like to use this in a JS session provided by the R package V8 #27

Open
tombisho opened this issue Jul 5, 2021 · 1 comment
Open

Comments

@tombisho
Copy link

tombisho commented Jul 5, 2021

I would be interested to know how difficult it would be to provide the magmajs behaviour in a JavaScript engine session running within an R session.

###Background:

The magmajs editor in MOLGENIS or Opal is fine for simple harmonisation. It is a good solution for harmonising as it can be used without the user having full access to the data. However using it for complex harmonisation can be challenging to debug and spot problems. We have been experimenting with generating synthetic data on the client side, which is a realistic representation of the real data, and that the user can have full access to. We then tried loading this into DSLite and using DataSHIELD functions to harmonise, which proved difficult because of the limited functions in DataSHIELD. Therefore the next idea is to try to use the V8 R package, which provides JavaScript in R. Then, the synthetic data can be put into the JavaScript session. JavaScript code can be written to do the harmonisation, and the user can have full access to data and see how things are working. When they are happy, the user can cut and paste the finished JS code into the MOLGENIS/Opal editor to run on the real data.
Question:

magmajs introduces features that are not available in standard JS. For example in magmajs we would refer to a column with the syntax $("smoking"). In V8, we can pull a dataset into JS but would refer to the columns as my_data.smoking.

V8 does offer the chance to pull JS libraries in, so we wondered if it is possible to pull the magmajs functionality for use with V8. This would mean the code written on the client side with full access to the synthetic data could be dropped into the MOLGENIS/Opal editor unchanged.

@tombisho tombisho changed the title I would like to use this in a JS session in R V8 I would like to use this in a JS session provided by the R package V8 Jul 5, 2021
@tombisho
Copy link
Author

tombisho commented Jul 6, 2021

I have managed to build the MagmaScript library with the following steps:

 git clone https://github.com/molgenis/molgenis-js-magma.git
 cd molgenis-js-magma/
 yarn install
 yarn build

I can now get the MagmaScript module to load in R V8:

ct_new$source("/home/vagrant/molgenis-js-magma/dist/MagmaScript.min.js")

I can also load some data into the session:

ct_new$assign("diamonds", diamonds)

But I am stuck what to do next. I know I must somehow get the $ notation up and running. I have created another bit of dummy data:

 const entity = {
    'id': 'A',
    'myStringAttributeName': 'abcde0123',
    'myIntAttributeName': 4,
    'height': 180,
    'name': 'caroline',
    'hasEars': true,
    'male': false,
    'female': true,
    'pregnant': true,
    'data': 1,
    'gender': {'_idValue': 'm', id: 'm', 'label': 'Male'}
  }

and it seems I need to do something like:

const $ = MagmaScript.$.bind(entity)

but it throws:

TypeError: Cannot call method 'bind' of undefined

Any help would be greatly appreciated!

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

No branches or pull requests

1 participant