How do I export a R/exams question with a tikzpicture to moodle? - r-exams

I'm using the Template logic: Interpretation of Logic Gates (Using TikZ) but I get the following error when I tried to export do moodle:
exams2moodle('logic.Rnw',name='TEST')
Erro: chunk 2
Error in magick_image_readpath(path, density, depth, strip, defines) :
rsession: not authorized `/tmp/RtmptUvxDm/file2d826c1a0925/tex2image/A.pdf' # error/constitute.c/ReadImage/412

Related

Error: object 'skim_without_charts' not found [duplicate]

I got the error message:
Error: object 'x' not found
Or a more complex version like
Error in mean(x) :
error in evaluating the argument 'x' in selecting a method for function 'mean': Error: object 'x' not found
What does this mean?
The error means that R could not find the variable mentioned in the error message.
The easiest way to reproduce the error is to type the name of a variable that doesn't exist. (If you've defined x already, use a different variable name.)
x
## Error: object 'x' not found
The more complex version of the error has the same cause: calling a function when x does not exist.
mean(x)
## Error in mean(x) :
## error in evaluating the argument 'x' in selecting a method for function 'mean': Error: object 'x' not found
Once the variable has been defined, the error will not occur.
x <- 1:5
x
## [1] 1 2 3 4 5
mean(x)
## [1] 3
You can check to see if a variable exists using ls or exists.
ls() # lists all the variables that have been defined
exists("x") # returns TRUE or FALSE, depending upon whether x has been defined.
Errors like this can occur when you are using non-standard evaluation. For example, when using subset, the error will occur if a column name is not present in the data frame to subset.
d <- data.frame(a = rnorm(5))
subset(d, b > 0)
## Error in eval(expr, envir, enclos) : object 'b' not found
The error can also occur if you use custom evaluation.
get("var", "package:stats") #returns the var function
get("var", "package:utils")
## Error in get("var", "package:utils") : object 'var' not found
In the second case, the var function cannot be found when R looks in the utils package's environment because utils is further down the search list than stats.
In more advanced use cases, you may wish to read:
The Scope section of the CRAN manual Intro to R and demo(scoping)
The Non-standard evaluation chapter of Advanced R
While executing multiple lines of code in R, you need to first select all the lines of code and then click on "Run".
This error usually comes up when we don't select our statements and click on "Run".
Let's discuss why an "object not found" error can be thrown in R in addition to explaining what it means. What it means (to many) is obvious: the variable in question, at least according to the R interpreter, has not yet been defined, but if you see your object in your code there can be multiple reasons for why this is happening:
check syntax of your declarations. If you mis-typed even one letter or used upper case instead of lower case in a later calling statement, then it won't match your original declaration and this error will occur.
Are you getting this error in a notebook or markdown document? You may simply need to re-run an earlier cell that has your declarations before running the current cell where you are calling the variable.
Are you trying to knit your R document and the variable works find when you run the cells but not when you knit the cells? If so - then you want to examine the snippet I am providing below for a possible side effect that triggers this error:
{r sourceDataProb1, echo=F, eval=F}
# some code here
The above snippet is from the beginning of an R markdown cell. If eval and echo are both set to False this can trigger an error when you try to knit the document. To clarify. I had a use case where I had left these flags as False because I thought i did not want my code echoed or its results to show in the markdown HTML I was generating. But since the variable was then used in later cells, this caused an error during knitting. Simple trial and error with T/F TRUE/FALSE flags can establish if this is the source of your error when it occurs in knitting an R markdown document from RStudio.
Lastly: did you remove the variable or clear it from memory after declaring it?
rm() removes the variable
hitting the broom icon in the evironment window of RStudio clearls everything in the current working environment
ls() can help you see what is active right now to look for a missing declaration.
exists("x") - as mentioned by another poster, can help you test a specific value in an environment with a very lengthy list of active variables
I had a similar problem with R-studio. When I tried to do my plots, this message was showing up.
Eventually I realised that the reason behind this was that my "window" for the plots was too small, and I had to make it bigger to "fit" all the plots inside!
Hope to help
I'm going to add this on here even though it's not a new question as it comes quite highly in the search results for the error:
As mentioned above, re checking syntax, if you're using dplyr, make sure you have all the %>% pipes at the end of the lines above the error, otherwise the contents of anything like a select statement won't pass down into the next part of the code block.

Unexplained R failure: Error: attempt to use zero-length variable name

I am trying to specify the size of a plot dynamically in RMarkdown. Because it is a facetted plot with a dynamic number of plots, the aspect ratio needs to change.
I'm using this code:
...
jobs_levels <- 9
```
#### Figure 3.1.1. Effect of Inidivdual Interventions in Living Rooms
```{r figure_3_3_1, fig.height=jobs_levels}
jobs_levels
print(figure_3_3_1)
```
For the sake of simplicity, I've hard coded the jobs_levels (the number of levels in the facetting factor). As you can see, I set the value very clearly,and then use it in the very next code chuck. I can see the value clear as day in the environment. It is 9. But I get this:
Error in eval(ele) : object 'jobs_levels' not found
> ```{r figure_3_3_1, fig.height=jobs_levels}
Error: attempt to use zero-length variable name
When I run this in batch mode, it crashes. Any idea what is going on with this?
I even put in the extra lines:
jobs_levels
to debug. EAch time I run one of those lines with cotrl enter, it evaluates right, but I see the error message again too...
The error message makes it look as though you are trying to evaluate the chunk header as R code. You had
```{r figure_3_3_1, fig.height=jobs_levels}
The first two backticks would be parsed as a zero length variable name, as the error message states.
You can't run R Markdown code as R code, you need to use rmarkdown::render or a related function to run it.

Error in readRDS(nsInfoFilePath) : error reading from connection

I found this error when I was dealing with the swirl assignment:
You're probably sick of it but rerun qplot again, this time with 4 arguments. The first 3 are the same as the last qplot command you just ran (price, data set equal to diamonds, and binwidth set equal to 18497/30). (Use the up arrow to save yourself some typing.) The fourth argument is fill set equal to cut. The shape of the histogram will be familiar, but it will be more colorful.
qplot(price, data = diamonds, binwidth = 18497/30, fill = cut)
Error in readRDS(nsInfoFilePath) : error reading from connection
I cannot solve this problem even after a long search on the internet
I encountered the same error while using ggplot2, even with very simple data and graph.
I traced the readRDS function with the following code :
trace(readRDS, quote(print(ls.str())))
which after running the ggplot code returned something like :
Tracing readRDS(metapath) on entry
file : chr "/home/username/R/x86_64-pc-linux-gnu-library/4.1/farver/Meta/package.rds"
refhook : NULL
I reinstalled the farver package, the error disappeared and I was finally able to plot the graph I wanted.
This package (and the package.rds file) was probably not installed correctly.
I found a similar issue and the tracing command here.

Error when using read.gml or read.graph to read a GML file

I am trying to load a file from the spanish building census (any of the files there will serve as an example, I'm using the 03001-ADSUBIA buildings one).
I have tried the read.gml function from the Multiplex package and get the following error:
read.gml("A.ES.SDGC.BU.03001.building.gml")
Error in which(("node" == arx) == TRUE)[1]:which(("edge" == arx) == TRUE)[1] :
NA/NaN argument
Then I tried the read.graph from the igraph package and also got an error:
read.graph("A.ES.SDGC.BU.46900.building.gml", format=c("gml"))
Error in .Call("R_igraph_read_graph_gml", file, PACKAGE = "igraph") :
At foreign.c:1127 : Parse error in GML file, line 1 (syntax error, unexpected STRING, expecting $end), Parse error
What am I doing wrong, and what can I do to fix it?
igraph and multiplex do not work because that is a different GML: Graph Modelling Language, as the name suggests, is for graphs (or networks). Your GML is Geography Markup Language.
Found an alternative on this post. However I would like to know why specific packages like multiplex or igraph cannot get the job done properly...
Code:
llayer<-ogrListLayers("A.ES.SDGC.BU.03001.building.gml")[1]
a<- readOGR(dsn="A.ES.SDGC.BU.46900.building.gml", layer=llayer, encoding = "UTF-8")
I have successfully used GEPHI to open gml files, and then use GEPHI'S export function (menu driven) to create 'new' gml files that open with igraph in R.
Details about GEPHI and the gml file definition are here.

R Sweave user defined function

I´m writing up a small function giving a combined conditional density and empirical cumulative distribution plot.
cdpl<-function(df,dep,indep){
attach(df)
cdplot(dep~indep,xlab=deparse(substitute(indep)),ylab=deparse(substitute(dep)))
g<-indep
ec<-ecdf(indep)
lines(knots(ec),as.numeric(names(table(ec(g)))),col="red",lw=3)
detach(df)
}
This works fine, however when I try to sweave it my luck is all out...
<<fig1,fig=T>>=
par(mfrow=c(1,2))
print(cdpl(tre,A,B))
print(cdpl(tre,A,C))
#
Sweave("re.rnw")
Writing to file re.tex
Processing code chunks ...
1 : echo term verbatim eps pdf (label=fig1)
Error: chunk 1 (label=fig1)
Error in model.frame.default(formula = dep ~ indep) :
invalid type (list) for variable 'dep'
How can this be when it works allright outside sweave?
//M
instead of attaching (causes all types of problems) pass the data frame as the data argument in cdplot and see if that works.

Resources