Persisting background data between pages

62 views
Skip to first unread message

Neil Natarajan

unread,
Aug 4, 2022, 9:18:20 AM8/4/22
to formr
Hi everyone,

I would like to define variables in R and persist them in the beckground between pages. At the moment, I'm defining the variable rands (it's defined as rands <- sample(2:20, 6, replace=FALSE)) in a code section of the label field of a note on the first page. For the rest of the first page, I am able to access rands. However, everything following the first submit button shows an error when I try to access rands.

The error message is: ## Error in eval_tidy(xs[[i]], unique_output): object 'rands' not found.

Does anyone know of a way around this?

Thanks,
Neil

Erin Buchanan

unread,
Aug 4, 2022, 11:00:29 AM8/4/22
to Neil Natarajan, formr

You would access it by using survey_name$rands on the next pages.  

 

So, if the first survey is called cheese, then you’d do cheese$rands.

 

erin

--
You received this message because you are subscribed to the Google Groups "formr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to formr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/formr/7cc654c3-6e89-4bd2-a1a4-f548f1f2d21dn%40googlegroups.com.

Neil Natarajan

unread,
Aug 4, 2022, 2:29:02 PM8/4/22
to formr
Erin,

Thanks so much for the prompt response!

I have just tried this and it also comes up blank.

What I'm doing now is using the block:

```{r}
test_survey$rands <- sample(2:20, 6, replace=FALSE)
```
in the label of a note, then a submit cell, then trying to display the random sequence in a second note with:

```{r, results='asis'}
cat(test_survey$rands)
```.

I have also tried replacing the first code block with:

```{r}
rands <- sample(2:20, 6, replace=FALSE)
```
In both cases, I can not see the sequence.

I am getting:

## Error in `$<-.data.frame`(`*tmp*`, rands, value = c(2L, 4L, 5L, 15L, 9L, : replacement has 6 rows, data has 1

in the first case and:

## Error: attempt to use zero-length variable name

in the second.


Any help would be much appreciated!

Kai Horstmann

unread,
Aug 4, 2022, 2:39:09 PM8/4/22
to Neil Natarajan, formr
Hi Neil, 

there are a few issues in the google doc:

The variable type should be „calculate“, not „note", and then you remove all the markdown stuff and change your code to: 

sample(2:20, 6, replace=FALSE)

Then name the variable „rands“ (in Col E)

Aftewards, you can access it as "survey$rands“, across surveys. 

I think this should work, hope it helps,

Best wishes,
Kai




Neil Natarajan

unread,
Aug 4, 2022, 3:08:26 PM8/4/22
to formr
Kai and I have workshopped this and the final answer is:

The variable should be „calculate“, but the code should be in the value column, not the label column. 

Though calling the variable works elsewhere, you cannot print the variable, e.g. "print(survey$rands)" does not work.

Keiland Cooper

unread,
Dec 15, 2022, 4:39:05 AM12/15/22
to formr
I had a similar issue, and I can have individual values persist across pages as outlined above. However I'd like to persist a dataframe across pages (and update it), rather than an individual value (more detail about it posted as an issue on github here). Nothing I've tried seems to do the trick. Is this possible? 

Thanks!
Keiland

Reply all
Reply to author
Forward
0 new messages