I have defined the variables and data necessary to generate a frequency table in RMarkdown, to export it to Moodle, using R-exams:
xsubio<-c(sample(5:35,5))
xsubi<-sort(xsubio)
frecuencias<-sample(0:30 ,5)
tabla<-data.frame(xsubi,frecuencias)
colnames(tabla)<-c(" Edades" ,"Personas")
Through chunk I generate the table:
```{r, eval=TRUE,echo=FALSE,results='asis',warning=FALSE,message=FALSE,error=FALSE}
library(exams)
print(xtable(tabla), include.rownames=FALSE)
```
When exporting to PDF, using exams2pdf, the table is displayed perfectly:
But, when exporting to Moodle, using exams2moodle, the table disappears:
What do I have to do to make it appear?
Problem: You have an exercise with formatting in Markdown and use xtable() to insert a table in LaTeX. This mixture of Markdown+LaTeX is no problem when converting the exercise to PDF. Internally, this preserves the LaTeX table and just converts the Markdown parts to LaTeX as well before rendering the LaTeX to PDF. However, the same is not possible automatically when converting the Markdown exercise to HTML for Moodle. The converter then does not separate the LaTeX part automatically to convert it to HTML.
In short: The different markups must be sufficiently in sync. Markdown+LaTeX markup for PDF output works and Markdown+HTML for HTML output works. But what would be even better is to have the markup fully in sync, i.e., LaTeX+LaTeX or Markdown+Markdown. Such exercises can then be rendered to either PDF or HTML automatically.
Possible solutions:
Markdown+Markdown: Markdown table markup in R/Markdown (Rmd) exercise
I would recommend that you simply produce tables in Markdown via knitr::kable() rather than xtable::xtable(). Thus, the code chunk for the table simply becomes
knitr::kable(tabla, format = "markdown")
and then the tables are rendered correctly in both PDF and HTML-based formats like Moodle.
LaTeX+LaTeX: LaTeX table markup in R/LaTeX (Rnw) exercise
In case you prefer to keep on generating LaTeX tables with xtable() another route would be to change the markup of the R/exams exercise to Rnw (R/LaTeX). See the First steps tutorial on the R/exams web page for how to do that.
Markdown+Adaptive: Choose the right table markup depending on the output format
Using the match_exams_call() function you can determine in a running exercise which exams2xyz() interface is being used to process it. So you could do
type <- if(match_exams_call() %in% c("exams2pdf", "exams2nops")) "latex" else "html"
print(xtable(tabla), type = type, ...)
Then either LaTeX or HTML format is produced by xtable().
All three solutions work in principle but I think Solution 1 (kable()) is the best and most robust in your case.
Bonus remark: If you are using R/exams >= 2.4-0 you can use exams2moodle(...,table = TRUE) to get nicer table formatting in Moodle.
I use the following code snippet (with type = "latex"), when I require a PDF output:
```{r, eval=TRUE, only.contents=TRUE, echo=FALSE, results='asis',
warning=FALSE, message=FALSE, error=FALSE, comment=FALSE}
library(exams)
library(xtable)
print(xtable(tabla), include.rownames=FALSE, type = "latex", comment=F)
```
And, when I require outputs for Moodle, I make use of the following code snippet (with type = "html"):
```{r, eval=TRUE, only.contents=TRUE, echo=FALSE, results='asis',
warning=FALSE, message=FALSE, error=FALSE, comment=FALSE}
library(exams)
library(xtable)
print(xtable(tabla), include.rownames=FALSE, type = "html",
comment=F)
```
Results in PDF:
Results for Moodle:
Is it possible to print some text + image with 4GL? I tried several approaches and nothing works for me. My code is below
DEFINE VARIABLE mMyMemPtr AS MEMPTR NO-UNDO.
FILE-INFO:FILE-NAME = "C:\image.png".
SET-SIZE(mMyMemPtr) = FILE-INFO:FILE-SIZE.
INPUT FROM VALUE(FILE-INFO:FILE-NAME) BINARY NO-MAP NO-CONVERT.
IMPORT mMyMemPtr.
INPUT CLOSE.
OUTPUT STREAM printstream TO PRINTER.
PUT "some text: " AT 1 SKIP.
PUT mMyMemPtr.
OUTPUT CLOSE.
Yes and no. It's possible to print images with ABL/Progress 4GL but not that way. You will need some other technique. The easiest way is probably to look into some kind of document format that supports printing. For example creating and printing:
a Word document via ActiveX automation (start here: https://knowledgebase.progress.com/articles/Article/P20445)
an HTML document
a PDF (there are freeware PDF-tools for Progress like the outdated http://www.oehive.org/pdfinclude.html - possibly others as well) or PostScript document
Via any report generator like Crystal, Eclipse BIRT etc.
I have files with extension .fid
I want to read the data off of the file with matlab preferably. Is there anyway to do this with a custom file format like this?
If not, is there any other way I can transform this custom file format into something else? such as .csv?
Not familiar with this file type, but if it's human-readable, if you can open it in text editor and see the data, then there shouldn't be a problem. You can textscan to import data, if it's properly formatted, or fileread to import the entire file as string. You can even use uiimport to import data in interactive mode. Check MATLAB documentation for Data import and export
I'm using the IPython Notebook. So far all I've got is:
from IPython.core.display import Image
Image(filename='gibbs.png')
Which indeed displays the image very well. What I want now is to add a few textboxes and arrows pointing at specific zones in the picture, ideally all within code (instead of drag-and-dropping).
Something tells me I'll probably have to do it in Matplotlib, but I want to know what are the best practices.
You could use matplotlib to do this. The annotate function will allow you to include arrows and text. If you want the text without the arrow, then omit the "arrowprops" part. If you want the arrow but not text, then just include an empty string.
Try this code:
import matplotlib.pyplot as plt
data = plt.imread('gibbs.png')
plt.imshow(data)
plt.annotate('Label A',xy=(81,130),xytext=(150,200),arrowprops=dict(facecolor='red'))
plt.show()
Here is the output that I get, assuming that you are using a png of J. Willard Gibbs:
I wish to show the knitR code in the final PDF together with its execution result.
I did not find yet a working way to fence "tripple-backticks"{r}..."tripple-backticks" blocks in the knitR code and see them as-is in the final PDF.
The backticks get interpreted whatever I do.
This is for tutorial purpose so that people see how to write knitR markdown. The use of html "pre" tags around the block of code leads to removal of the code.
for instance I wish to see this example fully first and then the result thereof
adding 4 spaces before each line like here does not work in RStudio and knit HTML fails
```{r test-haskell, engine='haskell', engine.path='ghc', cache=TRUE}
[x | x <- [1..10], odd x]
```
follow-up addition
I include here some RStudio Rmd code that leads to unexpected PDF content
in the pdf, the pre-code block simply disappeared.
The only fix I found is to invent a fake tag 'rmd' to fence the pieces of markdown I wish to keep as-is. I suspect this is a pandoc issue rather than knitr, unless there is a better way to fence code in knitr. The code I wish to keep can be any of bash, perl, R, or any other manguage used to process the data in the knitr tutorial.
my pandoc command was:
pandoc --variable=geometry:'top=1.5cm, bottom=1.5cm, left=2cm,
right=1cm' --variable=papersize:'a4paper' --number-sections
--table-of-contents --template=default.latex --highlight-style tango testrmd.md -o testrmd.pdf
Can it come from the template I used (default.latex)? It is the only template I found that meets my needs for vignette-like output. Same about 'tango' which is the only coloring scheme that shows some light background in code blocks.
As you see from the screenshots above I am a new-bee here (both in markdown and latex). Thanks for any help