R Error: object 'r library(magrittr)\n\tlibrary(dplyr)' not found

70 views
Skip to first unread message

Lucca Kühnel

unread,
May 4, 2022, 6:15:52 AM5/4/22
to formr
Hi all,
For our bachelor thesis we tried to implement a more comples r code (ratings of meals->matching meal-pairs on the basis of these ratings, to control for the personal preference for specific flavours etc). 

FormR gives us this error: R Error: object 'r library(magrittr)\n\tlibrary(dplyr)' not found

So therefore our question is: Does anyone know how FormR can load Packages from R properly? Like how can you code this in FormR? Or why does it not work with our Google Spreadsheet?

In the following you can see our code and how it is implemented in Form R.

Screenshot 2022-05-04 121305.pngScreenshot 2022-05-04 121223.png

Thank you so much for your help!

Best, Lucca

Kai Horstmann

unread,
May 4, 2022, 6:19:44 AM5/4/22
to Lucca Kühnel, formr
Hi Lucca, 

I thnk the error here is not with the package, but with the code. If you use a calculate item, you dont need to put `r …` there. Just call the functions, and maybe just add the package with package::function, for example psych::describe. 

Best wishes,
Kai 

Am 04.05.2022 um 12:15 schrieb Lucca Kühnel <kuehne...@gmail.com>:

Hi all,
For our bachelor thesis we tried to implement a more comples r code (ratings of meals->matching meal-pairs on the basis of these ratings, to control for the personal preference for specific flavours etc). 

FormR gives us this error: R Error: object 'r library(magrittr)\n\tlibrary(dplyr)' not found

So therefore our question is: Does anyone know how FormR can load Packages from R properly? Like how can you code this in FormR? Or why does it not work with our Google Spreadsheet?

In the following you can see our code and how it is implemented in Form R.

<Screenshot 2022-05-04 121305.png><Screenshot 2022-05-04 121223.png>

Thank you so much for your help!

Best, Lucca

--
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/00f17a6b-4417-4d5c-af2b-eb5d28a97a9dn%40googlegroups.com.
<Screenshot 2022-05-04 121223.png><Screenshot 2022-05-04 121305.png>

Message has been deleted
Message has been deleted

Ruben Arslan

unread,
May 6, 2022, 9:36:15 AM5/6/22
to Lucca Kühnel, formr
Replace 
install.packages("magrittr")
library(magrittr)
install.packages("dplyr")
library(dplyr)

with
library(dplyr)

you can't install packages, but dplyr is installed already and magrittr is part of dplyr.

Another problem you're likely to have: formr automatically makes data available for variables that you explicitly name in your code. But that is just a simple text look up.  It won't get you f_id_1 to f_id_20 based on this code.
cat1id[i] <- get(paste("f_id_", i, sep = ""))

Consider sth like 
cat1id[1] <- survey$f_id_1
cat1id[2] <- survey$f_id_2

or whatever works.

If you keep getting errors, please share the output from the debugger in a "Test run" with us, so we can debug with a test dataset. Or maybe that'll help you solve it on your own.

Best,

Ruben

On Fri, May 6, 2022 at 1:51 PM Lucca Kühnel <kuehne...@gmail.com> wrote:
Hi Kai,

Thank you so much for your input, highly appreciated. We tried it out but it is still showing us the same error. Do you - or anyone else - have an idea what part of our code/ google spreadsheet is incorrect?
Our initial beginning of the code was:
install.packages("magrittr")
library(magrittr)
install.packages("dplyr")
library(dplyr)


We tried out the following
magrittr::describe
dplyr::describe

Please notice our original code in the following. Maybe somebody can find the issue and show us what we did wrong:

install.packages("magrittr")
library(magrittr)
install.packages("dplyr")
library(dplyr)

cat1id <- vector(mode = 'list', length = 20)
cat1rate <- vector(mode = 'list', length = 20)
cat2id <- vector(mode = 'list', length = 20)
cat2rate <- vector(mode = 'list', length = 20)

for(i in 1:20)
{
cat1id[i] <- get(paste("f_id_", i, sep = ""))
cat1rate[i] <- get(paste("f_rate_", i, sep = ""))
cat2id[i] <- get(paste("v_id_", i, sep = ""))
cat2rate[i] <- get(paste("v_rate_", i, sep = ""))
}

cat1 = data.frame(unlist(cat1id), unlist(cat1rate))
names(cat1) = c("id", "rate")
cat2 = data.frame(unlist(cat2id), unlist(cat2rate))
names(cat2) = c("id", "rate")

matchlist<-expand.grid(c1=1:20,c2=1:20,stringsAsFactors=F)
matchlist$c1id<-cat1$id[matchlist$c1]
matchlist$c1rate<-cat1$rate[matchlist$c1]
matchlist$c2id<-cat2$id[matchlist$c2]
matchlist$c2rate<-cat2$rate[matchlist$c2]
matchlist$ratediff<-abs(matchlist$c2rate-matchlist$c1rate)

oppnearscorematch<-data.frame(c1id=rep(NA,20),c2id=rep(NA,20),stringsAsFactors=F)
for(i in 1:20){
currmatch<-matchlist[which.min(matchlist$ratediff),]
currmatch<-currmatch[sample(1:nrow(currmatch),1),]

matchlist%<>%filter(c1id!=currmatch$c1id & c2id!=currmatch$c2id)
oppnearscorematch$c1id[i]<-currmatch$c1id
oppnearscorematch$c2id[i]<-currmatch$c2id
}
oppnearscorematch$c1rate<-cat1$rate[match(oppnearscorematch$c1id,cat1$id)]
oppnearscorematch$c2rate<-cat2$rate[match(oppnearscorematch$c2id,cat2$id)]
oppnearscorematch$ratediff<-abs(oppnearscorematch$c2rate-oppnearscorematch$c1rate)

oppnearscorematch <- oppnearscorematch[sample(1:10), ]

Best,
Lucca

Reply all
Reply to author
Forward
Message has been deleted
0 new messages