# Error when adding "rds" data as the resource

**URL:** <https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366>\
**Category:** Analyst Support\
**Created:** [2 March 2021 13:11 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366 "2021-03-02T13:11:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HankCao](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HankCao](https://datashield.discourse.group/u/HankCao)\
**Post date:** [2 March 2021 13:11 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366/1 "2021-03-02T13:11:20Z")

</div>

Hi all,

I have uploaded an rds file into opal and added links to the resource.

 ![image](https://global.discourse-cdn.com/free1/uploads/datashield1/original/1X/234199ce76d01500487178f07a5d305aa33e4ea4.png)

From the client, the data can be accessed but the format can not be transformed.

```
> builder <- DSI::newDSLoginBuilder()
> builder$append(server="s2", url = "http://192.168.56.101:8080/", token = "DA1GFgwECYA38DmXndmJlaUmjjN4bxPB", driver = "OpalDriver")
> 
> logindata <- builder$build()
> datasources <- DSI::datashield.login(logins = logindata)
> 
> datashield.assign.resource(datasources,symbol="res",resource = "omics.opal1")
> datashield.assign.expr(conns = datasources, symbol = "rse", expr = quote(as.resource.object(res)))
> 
> datashield.errors()
> $s2
> [1] "Command 'as.resource.object(res)' failed on 's2': Error while evaluating 'is.null(base::assign('rse', value={resourcer::as.resource.object(res)}))' -> Error in load(path, envir = private$.env) : \n bad restore file magic number (file may be corrupted) -- no data loaded\n"

```

Any opinions were appreciated.

Regards,

Hank

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [2 March 2021 13:50 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366/2 "2021-03-02T13:50:27Z")

</div>

Hi,

It looks like you have declared a RData file although it is a RDS one. Loading a RDS file with `load()` will fail as reported by the error message. The RDS file needs to be read by `readRDS()`. These are different data file “resources”.

FYI, this is a test script to validate your resource outside of a context of Datashield + Opal, simpler to debug:

```auto
library(resourcer)
x <- installed.packages()
class(x)
saveRDS(x, file = "/tmp/x.rds")
res <- newResource(url = "file:///tmp/x.rds", format = "matrix")
client <- newResourceClient(res)
class(client)
as.resource.object(client)

```

Another tip for debugging is to verify what is the class of the symbol you have assigned in Datashield with `ds.class("res")`, it will tell you whether it is the appropriate resource client.

Yannick

---

<div class="post-metadata">

**Author:** ![HankCao](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HankCao](https://datashield.discourse.group/u/HankCao)\
**Post date:** [2 March 2021 13:58 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366/3 "2021-03-02T13:58:14Z")

</div>

Hi Yannick,

```
ds.class(x = "res", datasources = datasources)
  Aggregated (exists("res")) [===========================================================] 100% / 1s
  Aggregated (classDS("res")) [==========================================================] 100% / 1s
$s2
[1] "RDataFileResourceClient" "FileResourceClient" "ResourceClient" "R6"                     

```

This shows that opal indeed read the data in the format of “rData”. How can I tell opal using another reader?

Regards,

Hank

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [2 March 2021 14:04 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366/4 "2021-03-02T14:04:24Z")

</div>

It’s not Opal that reads the resource, it is the “resourcer” package. In Opal you only see some parameters to build the resource object.

In your case, edit the resource reference in Opal and select `Category: Data file` and `Type: RDS file - Opal`, save and try again.

Yannick

---

<div class="post-metadata">

**Author:** ![HankCao](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HankCao](https://datashield.discourse.group/u/HankCao)\
**Post date:** [2 March 2021 14:11 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366/5 "2021-03-02T14:11:28Z")

</div>

Hi Yannick,

I do not have the option of “RDS file - Opal”. My opal is 3.0.3, resourcer is 1.0.1 Is this due to the low version?

Regards, Hank

---

<div class="post-metadata">

**Author:** ![yannick](https://yyz2.discourse-cdn.com/free1/user_avatar/datashield.discourse.group/yannick/32/19_2.png) [@yannick](https://datashield.discourse.group/u/yannick)\
**Post date:** [2 March 2021 14:33 UTC](https://datashield.discourse.group/t/error-when-adding-rds-data-as-the-resource/366/6 "2021-03-02T14:33:49Z")

</div>

RDS support was added in resourcer 1.1.0 which is available in the CRAN.

> **[resourcer: Resource Resolver](https://cran.r-project.org/web/packages/resourcer/index.html)**
>
> A resource represents some data or a computation unit. It is described by a URL and credentials. This package proposes a Resource model with "resolver" and "client" classes to facilitate the access and the usage of the resources.

You can install the new version from the Administration \> R \> Packages page.

Yannick
