readxl (import excel file to R) error - r

When I typed the following line using readxl package, :
bluedata <- read_excel("data.xlsx", coffee)
I get the following error:
Error in standardise_sheet(sheet, range, sheets_fun(path)) :
object 'coffee' not found
What I want was to import the data in "coffee" sheet of the "data.xlsx" file.
Could any one help me to solve this problem?
Thanks!

It is cool that you are using readxl package, this is faster than normal way to read outside data.
I think you can find the answer yourself by typing
help("read.excel")
or
?"read.excel"
I can tell you the answer, but you will met thousands of another problem if you can not find answer on your own

Related

Does anyone know what this error message (from the 'readxl' package in R) means?

I'm trying to open an Excel worksheet in R using the 'readxl' package function 'read_excel'.
library(readxl)
Test <- read_excel("Test.xlsx",sheet = "Sheet1")
I've used the exact same bit of code on the exact same excel workbook many times over the past year, and it has never caused a problem. This time, though, I get:
Error: object ‘data_frame’ is not exported by 'namespace:vctrs'
I've tried calling the file different things, moving it to different locations, opening different files etc. but am now always getting this error with the read_excel function. I can usually work out what to do in response to an error message by searching for the relevant string in Google. However, I've tried searching for this error message, and haven't found anything that looks helpful yet. If anyone has any ideas, these would be much appreciated!
It looks like data_frame is relatively new to vctrs. You may need to update your vctrs package. You may have accidentally rolled back to an earlier version?
Seems it was added here:
vctrs 0.3.3 2020-08-27

R error message for unused argument (writexl)

I have simple code
library(writexl)
write_xlsx(dataset, "C:/adhoc/my_data.xlsx")
The above works, however when I try
library(writexl)
write_xlsx(dataset, "C:/adhoc/my_data.xlsx", append=TRUE)
I get an unused argument error. How can I fix?
If you look at the documentation ?write_xlsx there is not an append argument defined for this function, thus the error. It has been raised as a possible feature for that package and deemed not possible. You could read the spreadsheet, do the appending in R, and then re-write the full version.
Alternatively, perhaps you would be served by write.xlsx() from the xlsx package which does have this argument and might be suitable for your purposes?

Error when importing SAS xpt files in R

I am trying to import an xpt file into R using read.xport from both SASxport and foreign package but somehow I keep getting below error message:
Error in lookup.xport.inner(file) :
SAS transfer file has incorrect library header
The same error would also appear using sasxport.get() from Hmisc package. However, the file itself looks fine under SAS viewer on my PC. Has anyone encountered this problem before, or can you suggest of a solution? Thank you.
When openning the file using a text editor the header looks like this:
HEADER RECORD*******LIBRARY HEADER RECORD!!!!!!!000000000000000000000000000000 SAS SAS SASLIB 6.06 bsd4.2
Two years after I posted this question I recently found that there is a function read_xpt() in package haven that works like a miracle.
I guess the frame work of this package is totally different from previous packages.

readRDS fails to read in file in R. Is there an alternative?

I'm trying to read the RDS file I downloaded from here:
https://github.com/jcheng5/googleCharts/tree/master/inst/examples/bubble
However, when I try to load it into RStudio via:
data<- readRDS('/Users/nathanf/shinyCharts/healthexp.rds')
I get the Error: unknown input format.
I've searched and found a possible solution already posted on StackOverflow, but the solutions mentioned in it do not work.
Does not work:
readRDS(file) in R
Please note, I'm trying to do this with a freshly installed copy of R (3.2.1) on a Mac running Yosemite.
I've found articles online that say the readRDS function is now defunct. https://stat.ethz.ch/R-manual/R-devel/library/base/html/base-defunct.html
Sooooooo....dearest community, what should I do? Is there another way to read RDS files using a new function?
Any help would be much appreciated.
Thank you,
Nathan
I faced exactly the same problem and I can recommend switching from .rds objects into .RData objects. Simply:
save(random_forest1, "random_forest2.RData")
and then
load("random_forest2.RData")
Just for clarity, you will find your object named as random_forest1 after using load function

Using the "foreign" package in R

I need to import a STATA data set into R and I have downloaded the "foreign" package. Could you please tell me the steps to "load" the package into R and the steps to import the STATA dataset?
R helplist style answer: RTFM!
Statalist style answer: save your Stata file as usual. In R, type
help(package="foreign")
to find out what the commands are. The ones pertaining to Stata would have .dta in them, as .dta is Stata data file extension. read.dta(file="path/name.dta") should work on most occasions. If it does not, try saving your file from Stata as an old version (saveold filename.dta, replace).
BTW, it is Stata, not STATA. It's not an acronym, unlike SAS or SPSS... so you don't have to YELL.
P.S. As DWin correctly pointed out, you need to load the package:
library(foreign)
I assumed that since you seem to know R, remembering that won't be an issue.
It rather depends what you mean by "downloaded". You should not need to download anything, since 'foreign' is included in the standard R installation along with 'base', 'stats', 'utils', 'Matrix', and a few others like 'grDevices'. Whether or not you have already installed the 'foreign' package (unnecessarily) using one of the GUI commands, all you should need to do is:
library(foreign)
?read.dta # and run the example
I just had to deal with the same issue therefore the code:
library(foreign)
setwd(your working directory)
Please note that you have to set the working directory so that R knows where to look for your Stata dta dataset
And last the code:
read.dta("name of the dataset .dta")
A video for that topic:
https://www.youtube.com/watch?v=tCkCz4cu918

Resources