Problem with running an R-Markdown script in R while installing packages. I got an error while trying to knit the output of the document - r-markdown

First, I have installed the following packages in R-Markdown file
install.packages("tidyverse")
install.packages("ggplot2")
library(tidyverse)
library(ggplot2)
When I try to Knit to HTML or Word, I got this error-
*
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls:... withvisible->eval->eval->install.packages->contrib.url
Execution halted*
Your help is appreciated in advance. Thank you

#ViviG where do I have to put this {r eval=FALSE}?
This is my current query:
Visualization
You can also embed the visualization, for example:
install.packages("tidyverse")
install.packages("ggplot2")
install.packages("palmerpenguins")
library(tidyverse)
library(ggplot2)
library(palmerpenguins)
ggplot(data=penguins)+
geom_point(mapping=aes(x=flipper_length_mm,y=body_mass_g,color=species))+
labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species",
caption = "Data collected by Dr. Kristen Gorman")+
annotate("text",x=220,y=4000,label="The Gentoos are the largest",color="blue",fontface="bold",size=4.5,angle=30)
Same error displayed after knit-ing

Related

Using Latex in Django project with django_tex , pdflatex

I am trying to use Latex to build PDFs in Django project using django_tex , pdflatex. I have made setting such that in django setting.py , under INSTALLED_APPS, TEMPLATES . When server started running and the method is called , it is throwing an error while compiling the latex file .
Command 'cd "/tmp/tmpvk2or_tb" && pdflatex -interaction=batchmode texput.tex' returned non-zero exit status 127. is the error.
I am attaching my code part in Views.py and also my latex file .
Views.py
from django_tex.shortcuts import render_to_pdf
template_name = 'test.tex'
context = {'content':'this is the pdf content'}
return render_to_pdf(request, 'test.tex', context, filename='test.pdf')
test.tex
\documentclass{article}
\begin{document}
\section{ {{ content }} }
\end{document}
Can someone suggest something on this . And Is latex is the better option to generate pdfs with all backgrounds and all than using xhtml2pdf ?
Thanks in advance
Try to put the code in the settings
LATEX_INTERPRETER = 'pdflatex' and see if it solves.

render() versus Knit GUI for word_document

I am trying to knit a table created by kable() and produce a Word document. When I knit using the RStudio knit button, it works fine and produces a formatted table. When I use render(), it does not. It produces just a unformatted string of text. Here is a minimal example:
test.Rmd
---
title: "Test"
output:
word_document:
keep_md: true
---
```{r pressure2, echo=FALSE}
knitr::kable(mtcars)
```
The render() command is
rmarkdown::render("test.Rmd", clean=FALSE)
The pandoc command that is run by both the Knit button (RStudio) and the render() command is
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.docx --smart --highlight-style tango
I can see the problem in the test.utf8.md file produced by pandoc() when I run render(). The test.utf8.md file is an html table. I cannot see the test.utf8.md file produced by clicking the Knit button since that is not saved with keep_md=true. Only the test.md file is kept.
The RStudio Knit button must be changing the kable() format when output is word_document. If I change the kable() call to
knitr::kable(mtcars, format="markdown")
It works. The following sets the kable() format. I don't know what output format the user will select, so don't want to set format in the function call. Putting this with an if statement to detect if the output type is Word, fixes the problem.
options(knitr.table.format = 'markdown')

How to read .grd file as raster in R?

I want to read and stack several .grd files and export it as .nc file in R. I am using the following commands
library(raster)
library(ncdf4)
library(RNetCDF)
library(rgdal)
files <-list.files(path="G:/Gridded data/",
pattern="GRD", all.files=FALSE, full.names=TRUE,recursive=TRUE)
s <- stack(files)
rstack <- raster(files[1])
But it is giving the following error
Error in .local(.Object, ...) :
Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", :
Cannot create a RasterLayer object from this file.
Can anyone help? thanks in advance
I would try pattern="\\.grd$" (this means, the file ends on ".grd"). Or at least pattern="grd" instead of pattern="GRD". (or use ignore.case = TRUE)
files <- list.files(path="G:/Gridded data/", pattern="\\.grd$", full.names=TRUE,recursive=TRUE)

mx.viz.plot_network, cannot plot resnet

guys, I download resnet-152 from this url: http://data.mxnet.io/models/imagenet-11k/resnet-152/
Then, I try to plot this resnet with 152 layers in this way:
import mxnet as mx
sym, arg_params, aux_params = mx.model.load_checkpoint('resnet-152', 0)
pltn = mx.viz.plot_network(sym, shape = {'data': (1, 3, 224, 224)}, \
node_attrs = {'shape': 'oval', 'fixedsize': 'false'})
pltn.view('resnet-152')
However, the output pdf file is empty. I can plot LeNet, AlexNet and VGG, but what's wrong with the resnet? Thank you very much.
I can confirm that the code as written works with MXNet 1.1.0 and outputs a PDF that contains a graph for the whole neural network.

Unexpected EOF, using slate to parse PDF file on Python 2.7.12

I picked up O'Reiley's Data Wrangling with Python by Jacqueline Kazil and Katherine Karmul. In ch.5, pg.94, I'm running the following code.
import slate
pdf = 'EN-FINAL Table 9.pdf'
with open(pdf) as f:
doc = slate.PDF(f)
for page in doc[:2]:
print page
I'm using Windows 10, Python 2.7.12 , running slate 0.5.2, pdfminer 20140328 and successfully installed pip. I got the following result:
File "C:\Python27\lib\site-packages\pdfminer\psparser.py", line 215, in fillbuf
raise PSEOF('Unexpected EOF')
pdfminer.psparser.PSEOF: Unexpected EOF
I only know that EOF means 'end of file' and no more data can be read from data source. Does anybody have an idea as to what happened?
If anybody would like to see what file I'm trying to parse, it's right here:
https://github.com/jackiekazil/data-wrangling/tree/master/data/chp5
This solved it for me: https://stackoverflow.com/a/18262661/6843645
Your code would be:
import slate
pdf = 'EN-FINAL Table 9.pdf'
with open(pdf, 'rb') as f:
doc = slate.PDF(f)
for page in doc[:2]:
print page