# Error while evaluating resource on client side

**URL:** https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450
**Category:** Analyst Support
**Created:** [21 September 2021 07:36 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450 "2021-09-21T07:36:45Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![sztop](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@sztop](https://datashield.discourse.group/u/sztop)
#### Post date: [21 September 2021 07:36 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/1 "2021-09-21T07:36:45Z")

</div>

Hello,

we try to work around the problem discussed in [How to pass models between data scientists and nodes](https://datashield.discourse.group/t/how-to-pass-models-between-data-scientists-and-nodes-hospitals/440/10).

We saved our model as **model.RData** and **model.rds** files, then we assigned them as resources in our project as **R data** file - Opal and **RDS data** file -Opal (path set as : `/projects/my_project/model.RData`).

When we assign them in a R session:

`datashield.assign.resource(connections, symbol="D", resource="my_project.RESOURCE")`

and when we try to access them as

`datashield.assign.expr(connections, "T", expr=quote(as.resource.object(D)))`

or

`resource[[1]]$getValue()`

we encounter an error:

`Command as.resource.object(D) failed on server: Error while evaluating is.null(base::assign("T", value={resourcer::as.resource.object(D)})) -> Error in load(path,envir = private$.env): empty (zero-byte) input file`

These objects are saved exactly along the path set in the resource.

Any ideas?

Thank you in advance

---

<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: [21 September 2021 08:48 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/2 "2021-09-21T08:48:48Z")

</div>

Hi,

Most likely because the file retrieval from Opal failed (thus the empty file).

How have you created this resource: using the web interface or an R script?  
Can you verify that the credentials of the resource are correct? It must be a [personal access token](https://opaldoc.obiba.org/en/latest/web-user-guide/my-profile.html#personal-access-tokens).

Regards  
Yannick

---

<div class="post-metadata">

### Author: ![sztop](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@sztop](https://datashield.discourse.group/u/sztop)
#### Post date: [21 September 2021 09:14 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/3 "2021-09-21T09:14:15Z")

</div>

I created the resource using both web interface and R script, which ended up with the same effect.

I login to the opal using:

```auto
o <- opal.login("login", "password", token="TOKEN", url="URL")

```

TOKEN is the same as the one set on the resource.

---

<div class="post-metadata">

### Author: ![sztop](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@sztop](https://datashield.discourse.group/u/sztop)
#### Post date: [21 September 2021 09:16 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/4 "2021-09-21T09:16:11Z")

</div>

I had the same error when I set the resource as local object, which has no credentials required.

---

<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: [21 September 2021 11:58 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/5 "2021-09-21T11:58:26Z")

</div>

When you test with R, in [`opal.login()`](https://www.obiba.org/opalr/reference/opal.login.html), do not use both username/password and token, because token will be ignored. Use one authentication method or the other.

---

<div class="post-metadata">

### Author: ![sztop](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@sztop](https://datashield.discourse.group/u/sztop)
#### Post date: [21 September 2021 12:35 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/6 "2021-09-21T12:35:41Z")

</div>

And what about the local file resource? What path shoud the resource contain? I tried to access the resource via:

```auto
DSI::datashield.assign.resource(connections, "RESOURCE", "PROJ.RES")

```

```auto
DSI::datashield.assign.expr(connections, "DF", expr = quote(as.resource.data.frame(RESOURCE)))

```

I always get **test.csv** does not exist. It’s not clear to me what path should the resource contain. I have tried:

- `/projects/my_proj/test.csv`
- `/srv/fs/projects/my_proj/test.csv`
- `/test.csv`

Any Idea?

---

<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: [21 September 2021 13:30 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/7 "2021-09-21T13:30:34Z")

</div>

It is hard to tell, I do not know your setup.

- The local file resource has a path in the R server host, readable by the R server application.
- A path in Opal is only valid in the Opal context (i.e. accessed by Opal).

How do you verify your resource is accessible using R?

---

<div class="post-metadata">

### Author: ![xescriba](https://avatars.discourse-cdn.com/v4/letter/x/ee59a6/32.png) [@xescriba](https://datashield.discourse.group/u/xescriba)
#### Post date: [21 September 2021 13:57 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/8 "2021-09-21T13:57:43Z")

</div>

A small trick to know what your R server host has access to is doing system calls as the R session through `opalr`.

```auto
library(opalr)
o <- opal.login(url = "https://opal.XXXX.org", username = "user", password = "pass")
opal.execute(o, script = 'system("ls -lh /var/lib/rserver/work/projects/Athlete", intern = TRUE)')

```

That way you can be sure the local path were the files of interest are located and properly format the resource URL, as well as veryfying that the R session can actually see the path.

On the proposed code I can see the file `xxx.Rdata`; so I would create a resource as:

```auto
opal.resource_create(o, 'project', 'resource', 'file:///var/lib/rserver/work/projects/Athlete/xxx.Rdata',
                     format = 'Rdata')

```

I hope this can help. Xavier.

---

<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: [23 September 2021 07:44 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/9 "2021-09-23T07:44:18Z")

</div>

Hi,

Were you able to make it work?

As an example, the following script can help:

```auto
# Resource data
library(opalr)
o <- opal.login(username = "administrator", password = "password", url = "https://opal-demo.obiba.org")
# prepare project
if (!opal.project_exists(o, "test"))
  opal.project_create(o, "test")
# prepare data and upload in project's folder
saveRDS(mtcars, "mtcars.rds")
opal.file_upload(o, "mtcars.rds", "/projects/test")
unlink("mtcars.rds")
# make a personal access token
token <- opal.token_r_create(o, "mtcars", projects = "test")
# make the resource
opal.resource_create(o, "test", "mtcars", 
                     url = "opal+https://opal-demo.obiba.org/ws/files/projects/test/mtcars.rds",
                     format = "data.frame",
                     secret = token)
# verify
opal.resource_get(o, "test", "mtcars")
# set permission
opal.resource_perm_add(o, "test", "mtcars", "dsuser", permission = "view")
opal.logout(o)

```

Then use the resource in DataSHIELD:

```auto
# DataSHIELD
library(DSOpal)
library(dsBaseClient)
builder <- DSI::newDSLoginBuilder()
builder$append(server = "demo", user = "dsuser", password = "password", url = "https://opal-demo.obiba.org")
logindata <- builder$build()
conns <- datashield.login(logindata)
datashield.assign.resource(conns, "client", "test.mtcars")
datashield.assign.expr(conns, "df", expr = quote(as.resource.data.frame(client, strict = TRUE)))
ds.colnames("df")
datashield.logout(conns)

```

Regards  
Yannick

---

<div class="post-metadata">

### Author: ![gospelON](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@gospelON](https://datashield.discourse.group/u/gospelON)
#### Post date: [12 March 2025 18:35 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/10 "2025-03-12T18:35:28Z")

</div>

Hello Yannick, Thank you the script, am trying to load data as resource using this script but when i tried to use the resource i get an error datashield.assign.resource(conns, “client”, “test.mtcars1”) Assigned all resource (client ← …) [=======================\>------------------------] 50% / 0sError: $demo [1] “[Client error: (403) Forbidden] HTTP 403 Forbidden” . When i try with the administrator account i was able to use the resource. I also tried assigning permission to the user group but same error.

---

<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: [13 March 2025 12:45 UTC](https://datashield.discourse.group/t/error-while-evaluating-resource-on-client-side/450/11 "2025-03-13T12:45:02Z")

</div>

You get “Forbidden” error because user does not have the permission to use the Datashield service and/or the user does not have the permission to use this resource. See: [How to Manage Authentication and Authorizations — Opal documentation](https://opaldoc.obiba.org/en/latest/cookbook/r-datashield/authz.html)

Regards  
Yannick
