heatmaply + flexdashboard = Error in validateCssUnit(sizeInfo$width) : CSS units must be a single-element numeric or character vector - flexdashboard

---
title: heatmaply and flexdashboard don't mix...
output:
flexdashboard::flex_dashboard
---
### Chart 1
```{r}
library(heatmaply)
heatmaply(mtcars)
I saw this question (2018):
R shiny error: Error in html tools::validateCssUnit(height); CSS units must be a single-element numeric or character vector
presumably they are related...
Heatmaply is version: 1.1.1
flexdashboard is version: 0.5.2

I used to have this for code: ggplotly(x) which caused the error.
I added ggplotly(x, height=500, width=1000) and the error went away.

Related

How to fix "ERROR 1: Cannot get geotransform" in GDAL

I am trying to read values from a geoTiff and am using gdallocationinfo for that purpose.
However, when I try to do that, e.g with gdallocationinfo out.tif -wgs85 8.5 47.3, the following error occurs:
root#bc21abca5e07:/usr/src/app# gdallocationinfo out.tif -wgs84 8.5 47.3
ERROR 1: Cannot get geotransform
Note: if I leave the -wgs84 option away, I am able to read the values from the .tif. Also, the -geoloc function is resulting in the same output as -wgs84.
Is this a problem with the geoTiff? I have already tried this command on Windows and on Debian, resulting in the same output both times.
You can't "fix it" short of properly georeferencing your dataset.
The error means that your dataset lacks georeferencing information so GDAL is unable to convert the WGS84 coordinates to pixel coordinates.

How to call an image in beanshell?

I'm using following code to match my brightness and contrast between two images in ImageJ:
import ij.IJ;
import histogram2.HistogramMatcher;
// get first image
imp1 = IJ.openImage("http://imagej.nih.gov/ij/images/bridge.gif");
// get second image
imp2 = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif");
ip1 = imp1.getProcessor();
ip2 = imp2.getProcessor();
hist1 = ip1.getHistogram();
hist2 = ip2.getHistogram();
matcher = new HistogramMatcher();
newHist = matcher.matchHistograms(hist1, hist2);
ip1.applyTable(newHist);
imp1.setProcessor(ip1);
imp1.show();
imp2.show();
// show the histograms of both images
IJ.run(imp1, "Histogram", "");
IJ.run(imp2, "Histogram", "");`
but I get the following error and I don't know how to solve it I am very beginner in coding and especially in this language, I would highly appreciate to help me with this issue.
inline evaluation of: ``import ij.IJ; import histogram2.HistogramMatcher; ip1 = imp1.getProcessor(6th r . . . '' Encountered "( 6 th" at line 4, column 24.
at bsh.Parser.generateParseException(Parser.java:6106)
at bsh.Parser.jj_consume_token(Parser.java:5977)
at bsh.Parser.Statement(Parser.java:2699)
at bsh.Parser.BlockStatement(Parser.java:2819)
at bsh.Parser.Line(Parser.java:172)
at bsh.Interpreter.Line(Interpreter.java:1011)
at bsh.Interpreter.eval(Interpreter.java:641)
at bsh.Interpreter.eval(Interpreter.java:750)
at bsh.Interpreter.eval(Interpreter.java:739)
at org.scijava.plugins.scripting.beanshell.BeanshellScriptEngine.eval(BeanshellScriptEngine.java:68)
at org.scijava.script.ScriptModule.run(ScriptModule.java:157)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:163)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Your current code does not match the error you’re getting.
The functional part of this beanshell error is the following text:
ip1 = imp1.getProcessor(6th r . . . ''
Encountered "( 6 th" at line 4, column 24.
This tells us the beanshell script evaluated has invalid beanshell (Java) syntax starting after character 24 on line 4.
The closest line that matches this snippet from your code is not on line 4, and looks different:
ip1 = imp1.getProcessor();
Some things you can check:
Are you executing a different script by accident? Check your input for anything unexpected. You may be loading a different file or forgot to comment-out earlier tests.
Is there some caching involved somewhere in the pipeline that is running an older version of your code? Try to clean the cache/reload your project.

YAML issue when knitting to pdf

I have a paper written in rnotebook, which I want to knit to pdf.
this is the beginning of it, including the YAML:
---
title: "Are shifts between points of view challenging for readers? An examination of readers' eye movements in response to Woolf's *To the Lighthouse* and *Mrs Dalloway*"
author: "Giulia Grisot, Kathy Conklin, Violeta Sotirova - The University of Nottingham"
date: '`r format(Sys.time(), "%d %B %Y")`'
output:
html_notebook:
fig_caption: yes
force_captions: yes
#highlight: pygments
number_sections: false
theme: readable
# csl: sage-harvard.csl
csl: apa.csl
bibliography: library.bib
link-citations: yes
nocite: |
#Grisot2018
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
```{r, include=F}
library(tidyverse)
library(ggpubr)
```
# Abstract
The emergence of empirical approaches within stylistics has increased interest in how literary texts are processed by readers. Techniques of speech and thought representation represent an area ripe for empirical investigation in this respect, especially when these cause interpretative ambiguities.
I have installed tinytex, and I have got miktex installed and pandoc.
I have tried to just use the "knit to pdf" command in RStudio but it gives me this error and i don't know what to do
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: while scanning for the next token at line 4, column 31 found character that cannot start any token at line 4, column 31
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
Execution halted
I think this is down to the formatting in your yaml. When I knitted your code R Studio did some re-formatting of the title, but in the process replaced the ' with " in your date, causing the error. I don't have your .bib file so I can't test your exact code, but the following worked for me:
---
title: Are shifts between points of view challenging for readers? An examination of
readers' eye movements in response to Woolf's *To the Lighthouse* and *Mrs Dalloway*
author: "Giulia Grisot, Kathy Conklin, Violeta Sotirova - The University of Nottingham"
date: '`r format(Sys.time(), "%d %B %Y")`'
output:
pdf_document: default
html_notebook:
fig_caption: yes
force_captions: yes
number_sections: no
theme: readable
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
```{r, include=F}
library(tidyverse)
#library(ggpubr)
```
# Abstract

sqlQuery in R fails when called via source() [duplicate]

The following, when copied and pasted directly into R works fine:
> character_test <- function() print("R同时也被称为GNU S是一个强烈的功能性语言和环境,探索统计数据集,使许多从自定义数据图形显示...")
> character_test()
[1] "R同时也被称为GNU S是一个强烈的功能性语言和环境,探索统计数据集,使许多从自定义数据图形显示..."
However, if I make a file called character_test.R containing the EXACT SAME code, save it in UTF-8 encoding (so as to retain the special Chinese characters), then when I source() it in R, I get the following error:
> source(file="C:\\Users\\Tony\\Desktop\\character_test.R", encoding = "UTF-8")
Error in source(file = "C:\\Users\\Tony\\Desktop\\character_test.R", encoding = "utf-8") :
C:\Users\Tony\Desktop\character_test.R:3:0: unexpected end of input
1: character.test <- function() print("R
2:
^
In addition: Warning message:
In source(file = "C:\\Users\\Tony\\Desktop\\character_test.R", encoding = "UTF-8") :
invalid input found on input connection 'C:\Users\Tony\Desktop\character_test.R'
Any help you can offer in solving and helping me to understand what is going on here would be much appreciated.
> sessionInfo() # Windows 7 Pro x64
R version 2.12.1 (2010-12-16)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
loaded via a namespace (and not attached):
[1] tools_2.12.1
and
> l10n_info()
$MBCS
[1] FALSE
$`UTF-8`
[1] FALSE
$`Latin-1`
[1] TRUE
$codepage
[1] 1252
On R/Windows, source runs into problems with any UTF-8 characters that can't be represented in the current locale (or ANSI Code Page in Windows-speak). And unfortunately Windows doesn't have UTF-8 available as an ANSI code page--Windows has a technical limitation that ANSI code pages can only be one- or two-byte-per-character encodings, not variable-byte encodings like UTF-8.
This doesn't seem to be a fundamental, unsolvable problem--there's just something wrong with the source function. You can get 90% of the way there by doing this instead:
eval(parse(filename, encoding="UTF-8"))
This'll work almost exactly like source() with default arguments, but won't let you do echo=T, eval.print=T, etc.
We talked about this a lot in the comments to my previous post but I don't want this to get lost on page 3 of comments: You have to set the locale, it works with both input from the R-console (see screenshot in comments) as well as with input from file see this screenshot:
The file "myfile.r" contains:
russian <- function() print ("Американские с...");
The console contains:
source("myfile.r", encoding="utf-8")
> Error in source(".....
Sys.setlocale("LC_CTYPE","ru")
> [1] "Russian_Russia.1251"
russian()
[1] "Американские с..."
Note that the file-in fails and it points to the same character as the original poster's error (the one after "R). I can not do this with Chinese because i would have to install "Microsoft Pinyin IME 3.0", but the process is the same, you just replace the locale with "chinese" (the naming is a bit inconsistent, consult the documentation).
I think the problem lies with R. I can happily source UTF-8 files, or UCS-2LE files with many non-ASCII characters in. But some characters cause it to fail. For example the following
danish <- function() print("Skønt H. C. Andersens barndomsomgivelser var meget fattige, blev de i hans rige fantasi solbeskinnede.")
croatian <- function() print("Dodigović. Kako se Vi zovete?")
new_testament <- function() print("Ne provizu al vi trezorojn sur la tero, kie tineo kaj rusto konsumas, kaj jie ŝtelistoj trafosas kaj ŝtelas; sed provizu al vi trezoron en la ĉielo")
russian <- function() print ("Американские суда находятся в международных водах. Япония выразила серьезное беспокойство советскими действиями.")
is fine in both UTF-8 and UCS-2LE without the Russian line. But if that is included then it fails. I'm pointing the finger at R. Your Chinese text also appears to be too hard for R on Windows.
Locale seems irrelevant here. It's just a file, you tell it what encoding the file is, why should your locale matter?
For me (on windows) I do:
source.utf8 <- function(f) {
l <- readLines(f, encoding="UTF-8")
eval(parse(text=l),envir=.GlobalEnv)
}
It works fine.
Building on crow's answer, this solution makes RStudio's Source button work.
When hitting that Source button, RStudio executes source('myfile.r', encoding = 'UTF-8')), so overriding source makes the errors disappear and runs the code as expected:
source <- function(f, encoding = 'UTF-8') {
l <- readLines(f, encoding=encoding)
eval(parse(text=l),envir=.GlobalEnv)
}
You can then add that script to an .Rprofile file, so it will execute on startup.
I encounter this problem when a try to source a .R file containing some Chinese characters. In my case, I found that merely set "LC_CTYPE" to "chinese" is not enough. But setting "LC_ALL" to "chinese" works well.
Note that it's not enough to get encoding right when you read or write plain text file in Rstudio (or R?) with non-ASCII. The locale setting counts too.
PS. the command is Sys.setlocale(category = "LC_CTYPE",locale = "chinese"). Please replace locale value correspondingly.
On windows, when you copy-paste a unicode or utf-8 encoded string into a text-control that is set to single-byte-input (ascii... depending on locale), the unknown bytes will be replaced by questionmarks. If i take the first 4 characters of your string and copy-paste it into e.g. Notepad and then save it, the file becomes in hex:
52 3F 3F 3F 3F
what you have to do is find an editor which you can set to utf-8 before copy-pasting the text into it, then the saved file (of your first 4 characters) becomes:
52 E5 90 8C E6 97 B6 E4 B9 9F E8 A2 AB
This will then be recognized as valid utf-8 by [R].
I used "Notepad2" for trying this, but i am sure there are many more.

PDF Output with Knitr for Latex Equations

I am having trouble getting multi-line latex equations to successfully compile when using knitr in R Markdown. When I output as an HTML file it works but when I attempt to output as a PDF I get errors and it will not compile.
The following sample code illustrates the problem. Just change output:html_document to output: pdf_document. You'll see that in HTML output both Test 1 and Test 2 work. But in PDF output only Test 1 successfully compiles.
---
title: "Test"
date: "1/16/2018"
output: html_document
---
## R Markdown
Testing to see if a multi-line latex equation works.
#### Test 1:
$$ f(x) = x^5 + x^3 + x $$
$$ g(x) = y^{x+1} $$
#### Test 2:
\begin{align}
f(x) &= x^5 + x^3 + x \\
g(x) &= y^{x+1}
\end{align}
I am running Mac OS X - High Sierra and R Studio - Version 1.1.383
The following is the error I got:
Rule 'pdflatex': File changes, etc:
Non-existent destination files:
'Untitled.pdf'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex -halt-on-error -interaction=batchmode -recorder "Untitled.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
=== TeX engine is 'pdfTeX'
Latexmk: Errors, so I did not complete making targets
Collected error summary (may duplicate other messages):
pdflatex: Command for 'pdflatex' gave return code 1
Refer to 'Untitled.log' for details
Latexmk: Use the -f option to force complete processing,
unless error was exceeding maximum runs of latex/pdflatex.
! Paragraph ended before \align was complete.
<to be read again>
\par
l.112
Error: Failed to compile Untitled.tex. See Untitled.log for more info.
Execution halted