molgenis
8.2
8.2
  • Introduction
  • What is MOLGENIS
  • Try out MOLGENIS
  • Quick start (docker)
  • Find, view, query
    • Using the navigator
    • Using the search-all
    • Using the dataexplorer
    • Setup authentication
  • Data management
    • EMX format
    • Quickly import data
    • Advanced data import
    • Modify metadata
    • Questionnaires
    • Downloading data
    • Using expressions
  • Access control
    • Users
    • Groups and roles
    • Finegrained permissions
  • Data processing
    • Scripts
    • R
    • Python
    • Schedule jobs
  • Configuration
    • Settings
    • Customize MOLGENIS
    • Localization
    • Apps in MOLGENIS
    • Creating themes
    • Migration
  • Interoperability
    • Swagger specification
    • Data API
    • REST api v1
    • REST api v2
    • Files api
    • Import api
    • Permission api
    • Python-api client
    • R-api client
    • Beacon api
    • FAIR api
    • RSQL operators
  • For developers
    • Developing MOLGENIS
    • Developing frontend in MOLGENIS
    • Developing Apps in MOLGENIS
    • Using an IDE (Intellij)
    • Technologies
    • Dynamic decorators
    • Running the integration tests
    • Jobs
    • Security
  • For system administrators
Powered by GitBook
On this page
  • Overview example
  • login
  • logout
  • get
  • add
  • addAll
  • update
  • delete
  • deleteList
  • getEntityMetaData
  • getAttributeMetaData
  1. Interoperability

R-api client

PreviousPython-api clientNextBeacon api

Last updated 4 years ago

The MOLGENIS R API client allows you to retrieve, create, update and delete entities from within the environment.

Just add

source("http://molgenis.mydomain.example/molgenis.R")

at the top of your script and you can connect to a MOLGENIS server. Typically the first thing you do is login and the last thing is logout.

NOTE: For https connections use

eval(expr = parse(text = getURL("https://molgenis.mydomain.example/molgenis.R?molgenis-token=${molgenisToken}")))

NOTE: The MOLGENIS R-api client supports up to R-version 3.2.x

Overview example

source("http://molgenis.mydomain.example/molgenis.R")


molgenis.login("admin", "admin")

df <- molgenis.get("celiacsprue",
                   q = "celiac_weight>80 and celiac_height>180",
                   num = 1000,
                   attributes = c("celiac_weight", "celiac_height", "celiac_gender"))

plot(df$Celiac_Height ~ df$Celiac_Weight, col=df$Celiac_Gender)

molgenis.logout()

login

molgenis.login(username,password)

Login to the MOLGENIS REST API

logout

molgenis.logout()

Logout from the MOLGENIS REST API and destroy the session.

get

molgenis.get (entity, q = NULL, start = 0, num = 1000, attributes = NULL)

Retrieves entities and returns the result in a dataframe.

Parameter

Description

Required

Default

entity

The entity name

yes

q

Query string in rsql/fiql format (see below)

No

NULL

start

The index of the thirst row to return

No

0

num

The maximum number of rows to return (max 10000)

No

1000

attributes

Vector of attributenames(columns) to return

No

All attributes

sortColumn

attributeName of the column to sort on

No

NULL

sortOrder

sort order, 'ASC' of 'DESC'

No

NULL

Operator

Symbol

Logical AND

; or and

Logical OR

, or or

Group

( and )

Equal to

==

Less then

=lt= or <

Less then or equal to

=le= or <=

Greater than

=gt= or >

Greater tha or equal to

=ge= or >=

Argument can be a single value, or multiple values in parenthesis separated by comma. Value that doesn’t contain any reserved character or a white space can be unquoted, other arguments must be enclosed in single or double quotes.

Examples

molgenis.get("celiacsprue")
molgenis.get("celiacsprue", num = 100000, start = 1000)
molgenis.get("celiacsprue", attributes = c("Individual", "celiac_gender"))
molgenis.get("celiacsprue", q = "(celiac_weight>=80 and celiac_height<180) or (celiac_gender==Female)")
molgenis.get("celiacsprue", q = "(celiac_weight>=80;celiac_height<180),(celiac_gender==Female)")

add

molgenis.add(entity, ...)

Creates a new instance of an entity (i.e. a new row of the entity data table) and returns the id.

Parameter

Description

Required

entity

The entity name of the entity to create

yes

...

Var arg list of attribute names and values

yes

Example

id <- molgenis.add(entity = "Person", firstName = "Piet", lastName = "Paulusma")

addAll

molgenis.addAll(entity, rows)

Creates new instances of an entity (i.e. adds new rows to the entity data table) and returns the ids.

Parameter

Description

Required

entity

The entity name of the entity to create

yes

rows

data frame where each row represents an entity instance

yes

Example

firstName <- c("Piet", "Paulusma")
lastName <- c("Klaas", "de Vries")
df <- data.frame(firstName, lastName)

molgenis.addAll("Person", df)

update

molgenis.update(entity, id, ...)

Updates un existing entity

Parameter

Description

Required

entity

The entity name

yes

id

The id of the entity

Yes

...

Var arg list of attribute names and values

yes

Example

molgenis.update(entity = "Person", id = 8, firstName = "Pietje", lastName = "Paulusma")

delete

molgenis.delete(entity, id)

Deletes an entity.

Parameter

Description

Required

entity

The entity name

yes

id

The id of the entity

Yes

Example

molgenis.delete(entity = "Person", id = 8)

deleteList

molgenis.deleteList(entity, c("id1", "id2"))

Deletes a list of entities in an entityType.

Parameter

Description

Required

entity

The entityType name

yes

rows

List with ids of the rows

yes

Example

molgenis.deleteList(entity = "Person", rows = c("1", "2", "3"))

getEntityMetaData

molgenis.getEntityMetaData(entity)

Gets the entity metadata as list.

Example

meta <- molgenis.getEntityMetaData("celiacsprue")
meta$label

getAttributeMetaData

molgenis.getAttributeMetaData(entity, attribute)

Gets attribute metadata as list.

Parameter

Description

Required

entity

The entity name

yes

attribute

The name of the attribute

Yes

Example

attr <- molgenis.getAttributeMetaData(entity = "celiacsprue", attribute = "celiac_gender")
attr$fieldType

Supported RSQL/FIQL query operators (see )

R
https://github.com/jirutka/rsql-parser