0

I am creating a moodle question with R/exam package. When I compose the XML file from R I got the error message :

Error in split.default(questionlist, gr) : 
  first argument must be a vector 

I don't see why this error because the first argument is a vector. Can anyone help me please?

The sweave codes are given below

<<echo=FALSE, results=hide>>=
a<-sample(c("Un laboratoire","Un fabricant","Une firme de production"),1) 
b<-sample(c("d'une méthode contraceptive", "d'un contraceptif","d'un produit de contraception"),1)

nf<-sample(c(16,17,18,19,20,21,23,22,24,25),1)
age<-sample(c(25,30,35),1)
mu<-round(rnorm(1,mean=14.5,sd=sqrt(5.0625)),digits=1)
var.val<-round(rnorm(1,mean=5.0625,sd=sqrt(1.4)),digits=4)
avera<-round(rnorm(1,mean=13.03,sd=sqrt(5.0625)),digits=2)

var.echant<-round(rnorm(1,mean=6.32,sd=sqrt(1.4)),digits=2)
## QUESTION/SOLUTION
questions <- rep(list(""), 2)
questions[[1]] <- c("La  prise du contraceptif X a une influence sur la concentration en LH et sur l'ovulation", "Il n'ya pas d'influence de la  prise du contraceptif X sur la concentration en LH et sur l'ovulation")
questions[[2]]<-""
@

\begin{question}
SOME TEXT here
a) Quelle est l'hpothèse de recherche? ##ANSWER1##
b) La taille de l'échantillon est ##ANSWER2##
\end{question}

%% META-INFORMATION
%% \extype{cloze}
%% \exsolution{10|\Sexpr{nf}}
%% \exclozetype{schoice|num}
%% \extol{0.0001}
%% \exshuffle{TRUE}
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • If you still get the error on the R console, then it has nothing to do with LaTeX or sweave. I get no error, likely because you don't include `split` (from the error) anywhere in your code. Please edit your question (using [code-blocks](https://stackoverflow.com/editing-help#syntax-highlighting), too), do not include sweave/LaTeX (unless it only fails there, not on the console), and include your call to `split`. (And the error's reference to `gr` suggests we don't know about that variable, either.) – r2evans Aug 07 '19 at 16:21
  • Thank you for you quick response. But I don't understand where to use split, did you use it to run the codes I sent ? – Menus Nkurunziza Aug 07 '19 at 16:33
  • I think we're both confused about something. As I said before, your code above produces no errors or warnings for me. (Admittedly, I did not try to render the sweave document, since you have an R error I assume that only your R code is necessary to reproduce it.) – r2evans Aug 07 '19 at 16:49
  • The fact that your error explicitly includes `split.default(questionlist, gr)`, and your code produces a `questions` variable, I can safely infer that there is code elsewhere in your document that produces variables names `questionlist` and `gr`. While I don't want/need you to post your entire document, I think you should look at those two variables, perhaps with `class(questionlist)` (and/or `str(...)`, same for `gr`) to see what R says your variables look like. – r2evans Aug 07 '19 at 16:54
  • Oh sorry! You are right, there is a piece of code I did not send. The code I sent was from a sweave file say code.Rnw and this code did not show any warning even for me but there is a R script wich is built on the sweave file in this way: **myexam<-c("code",....)** ; **exam2moodle(myexam,n=3, converter="tth")** where ... are optional files. It is this last command run in R console or r script page that generated the error. – Menus Nkurunziza Aug 07 '19 at 18:29
  • Ok ... so it might be useful for you to read about [how to ask a question, well](https://stackoverflow.com/questions/5963269) (also: [mcve](https://stackoverflow.com/help/mcve) and [tags/r/info](https://stackoverflow.com/tags/r/info)). Bottom-line: now that you recognize the error is coming from that function, please recognize a few things: many (most?) of us are not aware of that function, so please provide any/all non-base packages that are relevant. A quick google revealed nothing, so perhaps that is custom code? If you want help with code, *you must provide the errant code*. – r2evans Aug 07 '19 at 22:08
  • This is not meant to be harsh, though I realize it may come across that way. We (I) cannot help if we don't know what is going on, and so far you have not provided code that evidences your problem. The biggest impact (of not asking a question "well") is that you do not get an answer quickly, and your question rapidly falls off the top-of-the-list, meaning fewer people will look at it again. If you don't have enough in a first-glance, many people never look back. Asking questions "well" is not often intuitive, it is learned. – r2evans Aug 07 '19 at 22:10

0 Answers0