tm readPDF: Error in file(con, "r") : cannot open the connection - r

I have tried the example code recommended in the tm::readPDF documentation:
library(tm)
if(all(file.exists(Sys.which(c("pdfinfo", "pdftotext"))))) {
uri <- system.file(file.path("doc", "tm.pdf"), package = "tm")
pdf <- readPDF(PdftotextOptions = "-layout")(elem = list(uri = uri),
language = "en",
id = "id1")
pdf[1:13]
}
But I get the following error (which occurs after calling the function returned by readPDF):
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\DOCUME~1\Tomas\LOCALS~1\Temp\RtmpU33iWo\pdfinfo31c2bd5762a': No such file or directory
Note that I have installed all xpdf binaries to current directory (but this is handled by the if condition).
EDIT: found out this is a bug. What would be the easiest workaround?

Did some debugging and see it fails in tm:::pdfinfo():
status <- system2("pdfinfo", shQuote(normalizePath(file)),
stdout = outfile)
This command doesn't create the outfile. According to Redirect system2 stdout to a file on windows this is a bug!

Related

failed to readLines and get error in file(con, "r") : cannot open the connection

Want to output a list of directories with ReadLines but returned an error of:
"Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:/Users/JJ/Desktop/features/002': Permission denied".
I have checked file.exists(), setwd, also shut down my antivirus, and change to the administrator as some similar post suggests, still no.
setwd("C:/Users/JJ/Desktop/features")
File_directory="C:/Users/JJ/Desktop/features"
Pathway=list.files(File_directory, full.names = T)
Ids_no = length(Pathway)
for (i in 1:ids_no){
Data_path = readLines(Pathway[i])
}
I tested readLines separately for a txt file, it worked fine. Also if I changed to readline, it return directories one by one. So what can do to resolve the problem with readLines?
for (i in 1:ids_no){
Data_path = readline(Pathway[i])
}
In the end, I used paste0 to replace the readLines to direct to my subject files.
Data_path = paste0(Pathway[i], "/feature.txt", sep = "")

One error when I run my R code about .stan file

I execute a code in R as following
model <- rstan::stan_model('ex_05_13.stan')
But there is an error as following:
Error in compileCode(f, code, language = language, verbose = verbose) : sh: c:/rtools40/mingw64/bin/g++: No such file or directorymake: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file492c7acd69ff.o] Error 127
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) : '-E' not found Error in sink(type = "output") : invalid connection
My ex_05_13.stan is syntactically correct. I don`t know why I cannot run my ".stan"? Thank you.
Face similar problem... Looks like a folder had previously made so the new R Tools cannot be installed and run the program properly

Can't read CSV file with R script

I'm still very new to R and I'm trying to read a moderate-size .csv file with a Script, but the script is unable to detect the file.
My code is at follows:
Saint<- read.csv("./Comp1.csv", stringsAsFactors = FALSE)
Saint
I have attempted several ways to indicate the file path. Including
path<- file.path("desktop", "saint", "Comp1.csv"
Then using the path variable in the read.csv function.
Also explicitly indicating the full path with forward slashes
It always throws the following error
> Saint<- read.csv("./Comp1.csv", stringsAsFactors = FALSE)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file './Comp1.csv': No such file or directory
>
> Saint
Error: object 'Saint' not found
Any ideas on what might be wrong here?

Importing a CSV file into R

I am Using a MACbook and new to R. I have the social network file on my desktop and I'm trying to get R to read it. I saved it as CSV
command typed:
sn.csv <- read.csv("C:\Users\Opemipo Akinosun\Desktop\social_network.csv", header = T)
I keep getting the following errors:
error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'C:/Users/Opemipo Akinosun/Desktop/social_network.csv': No such file or directory
the resource I'm learning with doesn't ask me to set my directory so I'm a little reluctant to doing that as suggested
You should use file.path that is OS-independant :
ff <- file.path("C:","Users","Opemipo Akinosun","Desktop","social_network.csv")
Then you can check if the file exists:
> file.exists(ff)
[1] FALSE
I worked and I could resolve the issue I was facing. Try changing the directory and then use the above code. So it will be as below
setwd("C:/Users/user/Desktop")
sn <- read.csv("social_network.csv" , header = TRUE)
sn
Run the above command and you should be all set to work further.

issue in getting data with getGEO in R

I want to download the soft file of the GPL6480 platform in R.
I've used this command :
gset<-getGEO("GPL6480")
but I faced with this problem:
curl: (6) Could not resolve host: www.ncbi.nlm.nih.gov
File stored at:
/tmp/RtmpbHgZqQ/GPL6480.soft
Error in file(fname, "r") : cannot open the connection
In addition: Warning messages:
1: In download.file(myurl, destfile, mode = mode, quiet = TRUE, method = getOption("download.file.method.GEOquery")) :
download had nonzero exit status
2: In file(fname, "r") :
cannot open file '/tmp/RtmpbHgZqQ/GPL6480.soft': No such file or directory
I googled for this problem but I can't find the answer. acctauly i don't know that what is the problem exactly.you should know that my connection to net is ok.
I'm using R version 3.2.0 on Ubuntu 14.04.2 trusty
tnx mansoor

Resources