Persisting background data between pages

Skip to first unread message

Neil Natarajan

Aug 4, 2022, 9:18:20 AMAug 4
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?


Erin Buchanan

Aug 4, 2022, 11:00:29 AMAug 4
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.



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
To view this discussion on the web visit

Neil Natarajan

Aug 4, 2022, 2:29:02 PMAug 4
to formr

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:

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'}

I have also tried replacing the first code block with:

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

I am getting:

## Error in `$<`(`*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

Aug 4, 2022, 2:39:09 PMAug 4
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,

Neil Natarajan

Aug 4, 2022, 3:08:26 PMAug 4
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.
Reply all
Reply to author
0 new messages