Cannot read data from an xlsx file in RStudio - r

I have installed the required packages - gdata and ggplot2 and I have installed perl.
library(gdata)
library(ggplot2)
# Read the data from the excel spreadsheet
df = data.frame(read.xls ("AssignmentData.xlsx", sheet = "Data", header = TRUE, perl = "C:\\Strawberry\\perl\\bin\\perl.exe"))
However when I run this I get the following error:
Error in xls2sep(xls, sheet, verbose = verbose, ..., method = method, :
Intermediate file 'C:\Users\CLAIRE~1\AppData\Local\Temp\RtmpE3UYWA\file8983d8e1efc.csv' missing!
In addition: Warning message:
running command '"C:\STRAWB~1\perl\bin\perl.exe" "C:/Users/Claire1992/Documents/R/win-library/3.1/gdata/perl/xls2csv.pl" "AssignmentData.xlsx" "C:\Users\CLAIRE~1\AppData\Local\Temp\RtmpE3UYWA\file8983d8e1efc.csv" "Data"' had status 2
Error in file.exists(tfn) : invalid 'file' argument

Thanks to #Stibu I realised I had to set my work directory. This is the command you use to run in Rstudio; setwd("C/Documents..."). The file path is where the excel file is located.

I had the issue but I solved it differently.
My problem was because my file was saved as Excel (extension .xls) but it was a txt file.
I corrected the file and I did not meet any other error with the R function.

Related

R openxlsx error using "loadWorkbook": WARNING: simpleWarning in unzip(file, exdir = xmlDir): error 1 in extracting from zip file

Attempting to load data from an Excel spreadsheet in R using openxlsx, I get the following error/warning,
WARNING: simpleWarning in unzip(file, exdir = xmlDir): error 1 in extracting from zip file. This is not a zipped file.
Why am I getting this error?
This error is not related to zip-issues. Instead, this is probably a file-lock error. Check to be certain that the workbook in question is not currently open. If so, close it and try again.

How to deal with errors for loading a rdata file?

I need the data of the .rdata file for text mining. These are my dataset. I don't know exactly what's in that file. The problem is i can't load it.
I tried to open the file with different windows computers but with the same errors. I used RStudio in the updated version. I google the error-Information but nothing worked. Because I can open other rdata files there should be no registry problem. I wanted to check in an other basic windows Editor to look what is in the file but there were only signs like: ‹ ìùuPo³6
’#p ÜÝ‚»»»[pw—…»»»»»†àînÁuA°E`!‡ßûîýí}æÌLMÕÌùæŸÝõTñÈ}÷ÝrõÕ½
¢hXˆ
I tried different possibilities to open the file in RStudio with different error informations as followed:
with load()
require("readr")
setwd("C:/Users/..")
options(stringsAsFactors = F)
load("file")
# Error in load("file") :
# bad restore file magic number (file may be corrupted) -- no data loaded
# In addition: Warning message:
# file ‘.rdata’ has magic number ''
# Use of save versions prior to 2 is deprecated
with source()
require("readr")
setwd("C:/Users/..")
options(stringsAsFactors = F)
source("file")
# Error in source("file") :
# file.rdata:1:1: unexpected input
# 1:
# ^
readRDS
setwd("C:/Users/..")
options(stringsAsFactors = F)
readRDS("file")
# Error in readRDS("file") : unknown input format

Error while trying to write a csv file

I'm trying to write a csv file in RStudio on a MacOS, but I'm getting this error:
Error: Failed to open '/Users/some.one/Documents/data'
and this is my code:
write_csv(dat, path_dat, na = "NA", append = FALSE, col_names = TRUE)
can someone maybe tell me what might cause such an error?
Edit:
dat ........... is a data frame
path_dat ...... is the path in the error : /Users/some.one/Documents/data
I would check that you have access to this directory. You can do via getwd()
If you don't, you can change the directory you're writing to via setwd(path_to_directory) and then run your write.csv function.

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.

Resources