Why doesn't the nops_scan function of the R package exams create zip file? - r-exams

I am trying to run the tutorial for written exams in the exams package (http://www.r-exams.org/tutorials/exams2nops/). Everything works fine until I am about to process the scanned documents using the nops_scan function, which normally should create a zip file.
In the console it says "Creating ZIP file", but nothing happens after that. Last output:
> nops_scan(dir = "nops_scan")
Loading required namespace: png
Reading PNG files:nops_scan1.png: Trimming PNG, rotating PNG,
extracting information, done.nops_scan2.png: Trimming PNG, rotating
PNG, extracting information, done.
Creating ZIP file:
... and then nothing happens.
I have tried to run dir("nops_scan") and it confirms that no zip file has been generated and placed in this folder.
The files in the tutorial are png-files, so what the tutorials says about running pdftk and ImageMagick, should not apply. From the tutorial: "Note that if there were PDF files that need to be scanned, then the PDF toolkit pdftk and the function convert from ImageMagick need to be available outside of R on the command line."
Could the problem still be related to the above comment about pdftk or ImageMagick? (Which program is used to create the zip files?) I do not know how to make these programs "available outside of R", so instruction on this would be appreciated!

The base zip() function from the tools package is used, see ?zip. If you are on Windows maybe you need to install the Rtools? These are available from CRAN at https://CRAN.R-project.org/bin/windows/Rtools/.
PDFTk and ImageMagick are not involved in this case, they are only needed to convert PDF files to PNG which can then be processed in R. (And just in case anybody else is looking for this information: http://www.R-exams.org/tutorials/installation/ provides links to installation files for these applications.)

Related

How to use libraries across an r notebook?

I wish to use libraries across multiple .Rmd files in an r notebook without having to reload the library each time.
An example: I have loaded the library kableExtra in the index.Rmd file but when I call it in another .Rmd file such as ExSum.Rmd I would get this error:
Error in Kable....: could not find funciton "kable" Calls:...
If I load the kableExtra library again this problem goes away. Is there a workaround?
R Markdown files are intended to be standalone, so you shouldn't do this. There are two workarounds that come close:
If you process your .Rmd files within the R console by running code like rmarkdown::render("file.Rmd") then any packages attached in the session will be available to the code in the .Rmd file.
You can put all the setup code (e.g. library(kableExtra)) into a file (called setup.R, for example), and source it into each document in the first code chunk using source('setup.R'). Every file will run the same setup, but you only need to type it once.
The second is the better approach.

How to download and unzip a raster zipped file directly in r from github

I am trying to download 'Landsat.rar` file (included 6 Landsat bands) and unzip it directly in r, but It doesn't work as I expected. Thank you for your help!
library(raster)
ls_url<-"https://github.com/tuyenhavan/Landsat-Data/blob/LS7/Landsat.rar"
temp<-tempfile()
download.file(ls_url,temp)
unzip(temp,"tif$")
myls<-stack("tif$")
Especially if you are using Windows, it might be that you need to use the binary mode in download.file:
download.file(ls_url, temp, mode="wb")
otherwise the file gets corrupted.
Also, the URL you are using is incorrect. You used the one for the web interface. If you want to get the file itself you need to use (check the link associated with the "Download" button):
https://github.com/tuyenhavan/Landsat-Data/raw/LS7/Landsat.rar
Finally, unzip() doesn't know how to deal with rar archive files. If you created this archive yourself, use the zip format instead; or unrar the file with another program (that you could call from R using system()).

Build .md vignette using devtools

I’m using knitr::rmarkdown (but knitr::knitr does the same) as my VignetteEngine. I then build my package vignette using devtools::build_vignettes().
This works, but only creates HTML and R output files in inst/doc. What I want is a Markdown output file, since only that can be displayed directly within the Github project pages (for HTML files, Github shows the source and for Rmd files it shows a rendered output but — obviously — without executing the R blocks).
I’ve tried finding out how to specify the output for custom VignetteEngines and I think that it should be possible (after all, other packages use this to build PDF vignettes, at a minimum) but I cannot find a way of doing this via devtools::build_vignettes. Is there no way around building the vignette manually (i.e. via knitr::knit or similar mechanisms that ignore the VignetteBuilder directives)?
I can’t find relevant information in the documentation/source either.
The only output formats for vignettes are HTML and PDF (and LaTeX, but it is converted to PDF, not displayed). Markdown isn't supported.
You can have arbitrary documentation files in your package (by convention you put them in inst/doc), but they aren't considered to be vignettes, so they won't be automatically built, functions like browseVignettes() will ignore them, etc.
To convert an Rmd file to md, just run knitr::knit on it.

knitR/RMD: select output folder

I'm using a RMD file to create a package vignette. My. rmd file is stored in
.../path_to_package/vignettes/vignette.rmd
When creating a PDF the last line in the R Markdown console window is "Output created: /tmp/....".
How is it possible to create the PDF directly in the vignettes folder and not in a /tmp/.. folder?
I'm using Ubuntu 14.04 LTS and R 3.3.0, rmarkdown 0.9.6 and knitr 1.13.
Regards,
Johannes
rmarkdown::render does indeed output to the same directory as the input folder by default, but you can override that by supplying an output_dir argument to it (and an output_file one if you'd like to specify a different filename to the input file too).
I'm not sure why the Knit button in RStudio is doing something different for you—in my case it also outputs to the same folder as the source (even when I haven't specified a working folder and my home directory is the default), and RStudio doesn't show the function it's calling when you click the button, so it's a little hard to be sure. I'd stick to using rmarkdown::render() with the specified arguments for now.
Instead use
devtools::build_vignettes()
It will automatically put the files where they're supposed to go. Also check out Hadley Wickham's guide. It rocks!

Use of .RDA files in R CRAN package 'extRemes'

I am using the CRAN package extRemes in R.
By the command extremes.gui() the extremes toolkit opens. Now, the thing I want to do is opening one of .RDA data files that is included in the package, for example PORTw.rda. Now following the steps described in the tutorial (can be found here) something goes wrong in reading the .RDA files.
I do the following:
In the toolkit go to 'File' and then click on 'Read Data'. Select the file 'PORTw.rda' in the folder 'data' under 'extRemes'.
Select in the follwing window under the heading File Type 'R source'. Keep the boxes Heading and Delimiter empty and save the file as PORTw.
When I press the OK button it gives the following error in R:
Error in source("C:/Users/jawissie/Downloads/Documents/R/win-library/2.15/extRemes/data/PORTw.rda") :
C:/Users/jawissie/Downloads/Documents/R/win-library/2.15/extRemes/data/PORTw.rda:4:3: unexpected input
3:
4: Ý9–
Also when I try to open one of the .RDA files from the extRemes package it shows unreadable content.
Does anybody know if I am doing something wrong or if the delivered .RDA files are not correct?
(The .dat files of the same package doesn't give any problem)
I was having the same problem. The html version of the tutorial provides a link to the original .r files at; http://www.isse.ucar.edu/extremevalues/data/index.html . Just follow the link to the PORTw.R file copy and past the URL into the Read Data dialogue box and the data will be read into the workspace as originally intended.
RDA files need to be loaded with 'load'. When you "read data" you are using 'read.table'.

Resources