saveWidget fails with pandoc error 67 in R - r

I've faced a problem with saving plotly diagram p as html file, when the filename name is not in English:
htmlwidgets::saveWidget(p, paste0(name, "_all.html"))
For English filenames it works just fine, but when name variable contains Russian characters it fails with error:
pandoc.exe: Could not fetch 28%E1_all_files/htmlwidgets-0.9/htmlwidgets.js
28пїЅ_all_files/htmlwidgets-0.9/htmlwidgets.js: openBinaryFile:
does not exist (No such file or directory)
Error: pandoc document conversion failed with error 67
In this example
> name
[1] "28б"
Is there a way to fix that problem?
Thank You very much.

Related

Error in df_parse_dta_file(): Failed to parse C:/Users/folder/data.dta: This version of the file format is not supported

I wanted to read in a .dta file in R in order to convert it to a .csv file. First, I tried to do so by using the foreign package, but it reported:
Error in read.dta(file): not a Stata version 5-12 .dta file
So I tried to do it by using teh haven package, but that also failed and reported:
Error in df_parse_dta_file(spec, encoding, cols_skip, n_max, skip, name_repair = .name_repair) : Failed to parse C:/Users/folder/data.dta: This version of the file format is not supported
I also tried to convert it with the rio package:
install.packages("rio")
library(rio)
install_formats()
convert("file.dta","file.csv")
but it reported:
Error in arg_reconcile(haven::read_dta, file = file, ..., .docall = TRUE, :
Failed to parse C:/Users/folder/data.dta: This version of the file format is not supported.
This error was generated by: haven::read_dta
With the following arguments:
"._costs.dta"
Does anyone know how to import such .dta files in R so that one can convert a .csv file ?
PS: The preamble of the .dta-file looks like this:
<stata_dta>118LSFM 23 Apr 2019 16:22
Try adding encoding = "UTF-8" or encoding = "Latin1" inside the read_dta() function to tell R import same data without encoding into numbers. It might take a little while to clean data tho :(

For loop in function printing png files

I am trying to make a for-loop with a function pathway that prints a png in the current directory. The i is rownames in paths.hsa.my. My example below did not yield anything, please see the error below.
library("pathview")
for(i in rownames(paths.hsa.my)){
pathview(inn.m[,1],pathway.id = "i",species = "hsa")
}
head of my input:
head(rownames(paths.hsa.my))
[1] "hsa00010" "hsa00020" "hsa00030" "hsa00040" "hsa00051" "hsa00052"
Here is my error:
Warning: Failed to download KEGG xml/png files, hsai skipped!
Info: Downloading xml files for hsai, 1/1 pathways..
Warning: Download of hsai xml file failed!
This pathway may not exist!

error loading csv file for R

when i loading csv file for R, i can see the error
but i don't know why this happening
i wrote following code:
setwd("C:\\Users\\규남\\Desktop\\twitter")
library(KoNLP)
useSejongDic()
txt <- readLines(file("test.csv"))
and, this error appear
txt <- readLines(file("test.csv"))
Error in readLines(file("test.csv")) : cannot open the connection
In addition: Warning message:
In readLines(file("test.csv")) :
cannot open file 'test.csv': No such file or directory
why this happening?
file directory is not wrong, and that file in the folder
[enter image description here][1]
please see this
i restart Rstudio, even notebook power
but error appear again
how to i load that csv file?
and why this happening?
here is result useing getwd() function
[1] "C:/Users/규남/Desktop/twitter"
Warning message:
closing unused connection 3 (test.csv)
[1]: http://i.stack.imgur.com/xkFkt.png
When working through these problems I like to use the file.path() function. Look at the documentation, but it makes certain that the separator characters that are used in the string are what R is expecting.
Try:
path <- file.path("C:", "Users", "규남", "Desktop", "twitter")
setwd(path)
library(KoNLP)
useSejongDic()
txt <- readLines(file("test.csv"))

Error with tex2docx function from reports R package

I'm trying to reproduce the example for tex2docx function in reports R package and getting the following error.
DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex",
package = "reports")
BIB <- system.file("extdata/docs/example.bib", package = "reports")
tex2docx(DOC, file.path(getwd(), "test.docx"), path = NULL, bib.loc = BIB)
Error Message
pandoc.exe: Error reading bibliography `C:/Users/Muhammad'
citeproc: the format of the bibliographic database could not be recognized
using the file extension.
docx file generated!
Warning message:
running command 'C:\Users\MUHAMM~1\AppData\Local\Pandoc\pandoc.exe -s C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/doc_library/apa6.qual_tex/doc.tex -o C:/Users/Muhammad Yaseen/Documents/test.docx --bibliography=C:/Users/Muhammad Yaseen/R/win-library/3.0/reports/extdata/docs/example.bib' had status 23
I wonder how to get tex2docx function in reports R package working properly.
As described in the above comments, the error is caused by passing a filename/path including some spaces that are nor escaped, nor quoted. A workaround could be wrapping all file paths and names inside of shQuote before passing to the command line with system.
Code: https://github.com/trinker/reports/pull/31
Demo:
Loading package
library(reports)
Creating a dummy dir with a space in the name that would hold the bib file
dir.create('foo bar')
file.copy(system.file("extdata/docs/example.bib", package = "reports"), 'foo bar/example.bib')
Specifying the source and the copied bib file:
DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex", package = "reports")
BIB <- 'foo bar/example.bib'
Running the test:
tex2docx(DOC, file.path(getwd(), "test2.docx"), path = NULL, bib.loc = BIB)
Disclaimer: I tried to test this pull request, but I could not setup an environment with all the needed tools to run R CMD check with vignettes and everything else after all in 5 mins (sorry but being on vacation right now and just enjoying the siesta after lunch), so please consider this pull request as "untested" -- although it should work.

"Unrecognized escape in character string" while attempting to read a CSV file

I am trying to import a .csv file, so that I can follow along with this video: R ggplot2 Graphics Histograms.
I installed all proper packages including ggplot and related packages. The first instruction in the video says to type afl.df=read.csv("afl_2003_2007.csv")
So, I downloaded afl_2003_2007.csv file, and I tried all the below, which was basically putting the file in different directories (shared drive, then C drive, etc.). I also tried using setwd, but no luck.
I am using R in windows.
Here's what I tried, and the errors I got:
> afl.df=read.csv("afl_2003_2007.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'afl_2003_2007.csv': No such file or directory
> afl.df=read.csv("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming\afl_2003_2007.csv")
Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l"
> afl.df=read.csv("C:\Users\lopez235\Local-NOTBackedUp\R Files Local\afl_2003_2007.csv")
Error: '\U' used without hex digits in character string starting "C:\U"
> setwd("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming\afl_2003_2007.csv")
Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l"
> setwd("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming")
Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l"
> setwd("C:\Users\lopez235\Local-NOTBackedUp\R Files Local")
Error: '\U' used without hex digits in character string starting "C:\U"
Use / instead of \ in your path:
afl.df=read.csv("C:/Users/lopez235/Local-NOTBackedUp/R Files Local/afl_2003_2007.csv")
When encountering issues with importing datasets I prefer to use file.choose() and then pick my file manually.
For example :
newdataset <- read.csv(file.choose(), header = T)
a window asking you to selext your file manually will pop-up and header = T (or TRUE) tells R that these are the variable names. If you have data write header = FALSE.
If you want to confirm that now R knows which are the variable names you can call:
names(newdataset)
You can use the \\ instead of \
afl.df=read.csv("C:\\Users\\lopez235\\Local-NOTBackedUp\\R Files Local\\afl_2003_2007.csv")

Resources