--- title: "Introduction to rspacer" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Introduction to rspacer} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- The goal of rspacer is to "wrap" the [RSpace API](https://community.researchspace.com/public/apiDocs), that is, allow you to use the API directly from R using convenience functions. **This package (and its documentation) is a work-in-progress. Contributions are welcome!** ## Setting up rspacer To use rspacer it needs to know two things: 1. The API URL for your RSpace instance (this is typically the URL of your RSpace instance followed by `api/v1`, e.g., `https://leiden.researchspace.com/api/v1`) 2. Your API key, which is an authentication token you can use instead of your username and password. To create an API key go to 'Manage API Key' section of your RSpace profile page (MyRSpace -> My Profile). **You should keep your API key private.** You can regenerate an API key at any time, which will invalidate the old key. You can use the `set_api_url()` and `set_api_key()` functions to make these available to rspacer in the current session. To make this information persistent you can store it in environment variables. An easy way to do this is with `usethis::edit_r_environ()`; in the file that opens, you should add the following lines (insert your own URL and key): ``` RSPACE_API_URL="https://leiden.researchspace.com/api/v1" RSPACE_API_KEY="" ``` After saving the file and restarting R, you should now be able to run ``` r library(rspacer) api_status() ``` ``` ## $message ## [1] "OK" ## ## $rspaceVersion ## [1] "1.114.0" ``` ## Functionality ### Folders Now you can use rspacer to interact with your RSpace Workspace. For example, `folder_tree()` will show you the content of your Workspace as a tibble: ``` r folder_tree() ``` ``` ## # A tibble: 10 × 7 ## id globalId name created lastModified type owner ## ## 1 356307 SD356307 Gerhard Burger 2024-01-17 14:56:22 2024-01-17 15:04:39 DOCUMENT Gerhard Burger ## 2 260004 FL260004 LACDR RDM 2023-11-06 10:19:59 2023-11-06 10:19:59 FOLDER Gerhard Burger ## 3 242175 FL242175 GABi001_EMP_regulation 2023-05-30 10:14:51 2023-06-14 12:30:47 FOLDER Gerhard Burger ## 4 242400 FL242400 Ontologies 2023-06-01 07:23:10 2023-06-01 07:23:10 FOLDER Gerhard Burger ## 5 242398 FL242398 Api Inbox 2023-06-01 07:23:08 2023-06-01 07:23:08 FOLDER Gerhard Burger ## 6 242182 FL242182 Publications 2023-05-30 11:07:25 2023-05-30 11:07:25 FOLDER Gerhard Burger ## 7 21961 FL21961 DDS2 Data management 2023-03-16 09:50:33 2023-03-16 09:50:33 FOLDER Gerhard Burger ## 8 7833 FL7833 Templates 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 9 7819 GF7819 Gallery 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 10 7814 FL7814 Shared 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ``` You can also specify an id or Unique ID (`globalId`) to show the contents of a specific folder: ``` r folder_tree(7819) ``` ``` ## # A tibble: 8 × 7 ## id globalId name created lastModified type owner ## ## 1 7828 GF7828 Snippets 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 2 7827 GF7827 PdfDocuments 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 3 7826 GF7826 Miscellaneous 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 4 7825 GF7825 Documents 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 5 7824 GF7824 Chemistry 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 6 7823 GF7823 Videos 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 7 7822 GF7822 Audios 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ## 8 7820 GF7820 Images 2022-12-22 12:32:22 2022-12-22 12:32:22 FOLDER Gerhard Burger ``` ### Documents #### Search You can search for documents using the `document_search()` function: ``` r document_search("test") ``` ``` ## # A tibble: 50 × 10 ## id globalId name created lastModified parentFolderId tags tagMetaData form owner ## ## 1 424078 SD424078 test 2025-10-17 10:21:21 2025-10-17 10:21:27 242398 rspa… rspacer Basi… Gerh… ## 2 424072 SD424072 test 2025-10-17 09:21:55 2025-10-17 09:22:01 242398 rspa… rspacer Basi… Gerh… ## 3 422915 SD422915 251001_test_Sir… 2025-09-30 08:33:22 2025-10-07 11:51:30 NA Basi… Max … ## 4 421333 SD421333 250901_compare_… 2025-09-01 09:06:12 2025-09-10 13:16:24 NA Basi… Max … ## 5 420651 SD420651 250820_Surival_… 2025-08-19 14:34:17 2025-09-09 12:37:52 NA Basi… Max … ## 6 421114 SD421114 250829_test_cel… 2025-08-28 12:47:23 2025-09-09 12:06:32 NA Basi… Max … ## 7 421016 SD421016 250827_SAS_Kolf… 2025-08-27 07:29:23 2025-08-29 11:06:20 NA Basi… Max … ## 8 421238 SD421238 2025_08_25_SA00… 2025-08-29 08:59:39 2025-08-29 09:10:11 NA Basi… Serk… ## 9 419599 SD419599 250805_Surival_… 2025-08-05 11:25:24 2025-08-19 09:47:40 NA Basi… Max … ## 10 419593 SD419593 250805_Compare_… 2025-08-05 09:24:31 2025-08-19 09:37:45 NA Basi… Max … ## # ℹ 40 more rows ``` #### Retrieve You can retrieve documents using ``` r res <- document_retrieve("SD356307") summary(res) ``` ``` ## Length Class Mode ## id 1 -none- numeric ## globalId 1 -none- character ## name 1 -none- character ## created 1 -none- character ## lastModified 1 -none- character ## parentFolderId 1 -none- numeric ## signed 1 -none- logical ## tags 0 -none- NULL ## tagMetaData 0 -none- NULL ## form 10 -none- list ## owner 10 -none- list ## fields 8 -none- list ## _links 1 -none- list ``` The result is json converted to an R list, to get the field information you could use ``` r library(tidyverse) library(gt) res$fields |> fields_to_data_frame() |> gt() |> fmt_markdown(columns = c(content)) ```
id globalId name type content lastModified columnIndex files listOfMaterials _links
1873444 FD1873444 Template Used string LACDR-ISA - Contact v0.2.0 2024-01-17 14:56:22.625 0 NA NA NA
1873445 FD1873445 Name string Gerhard A. Burger 2024-01-17 14:56:39.641 1 NA NA NA
1873446 FD1873446 Email string g.a.burger@lacdr.leidenuniv.nl 2024-01-17 14:57:02.811 2 NA NA NA
1873447 FD1873447 Phone string 2024-01-17 14:56:22.625 3 NA NA NA
1873448 FD1873448 ORCID string 0000-0003-1062-5576 2024-01-17 14:59:29.511 4 NA NA NA
1873449 FD1873449 Address text Gorlaeus Building
Einsteinweg 55
2333 CC Leiden
Room number GE2.05
2024-01-17 14:57:49.379 5 NA NA NA
1873450 FD1873450 Affiliation string Leiden University 2024-01-17 14:59:13.433 6 NA NA NA
1873451 FD1873451 Roles text 2024-01-17 14:56:22.625 7 NA NA NA
#### Create Creating (structured) documents is slightly more involved, see the Articles tab for detailed instructions.