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.
Related
So I'm rather new to R, and I'm learning how to mine text from this handy website: https://eight2late.wordpress.com/2015/05/27/a-gentle-introduction-to-text-mining-using-r/
I do have my own text set of .doc, .docx, and .xlsx files and I'm trying to mine them. They're located in a folder in my working directory called 'files', but I have already encountered an error after simply writing a few lines of code.
The code I have so far is:
library(tm)
library(readtext)
data = readtext('files')
At this point, after waiting for 25 seconds or so, I get the error:
Error: System call to 'antiword' failed (1): The Big Block Depot is damaged
and the code stops running there.
I have tried searching online for solutions but it seems like a fairly rare error and so I only found 1 possible solution at https://github.com/ropensci/antiword/issues/1 but that did not work for me.
This solution suggested that one of my files were corrupt, and suggested using the code
fixInNamespace(antiword, pos="package:antiword")
to change the error to a warning to not interrupt the reading of the files. I tried that, and at first it raised the error of
Error in as.environment(pos):
no item called "package:antiword" on the search list
After which, I loaded the antiword library with a library(antiword) and changed the stop( to a warning(. However, when I ran the data = readtext('files') line again, it immediately raised the error
Error in is_windows() : could not find function "is_windows"
I'm at a loss here! Any help would be appreciated. Should I be using another package in this case?
I had the same problem with my code, where I tried to get a doc. file in R. I also used the readtext library. What helped me was converting the Word documents I was trying to get into R from doc. to docx. When I ran the same code after it worked.
I receive this message when I try to install "XLConnect" in R. I am trying to use some data from excel, and I don't know how else to load it into the program.
I'm completely new to R and programming, so any help is greatly appreciated!
This usually happens when there is a typo in the package name. The code below should work. My guess is that the capitalization might have been off when you tried it?
install.packages("XLConnect")
I'm reasonably sure that you had spaces on either side of term "XLConnect". At least that is what your error message is telling us. If trying what Mallick suggested does not succeed, then [edit] to include exact copies of any error message in the body of the question.
Other ways to transfer data from Excel to R include copying to the Clipboard or exporting as a '.csv' file. There must be hundreds of questions and answers about the Excel - to - R Highway Eternal Resurfacing Project. One more recent addition is the readxl package (function is read_excel) and that choice doesn't have the Java version dependencies that cause trouble for some XLConnect useRs.
I have to work with GAMS and R to extract data however I am a new R user and never have used GAMS before. I need to download a package called CSV_GDX_tools.exe and I have no idea what that is...
When I try to install it in R, I get this error message:
Warning in install.packages :
package ‘CSV_GDX_tools.exe’ is not available (for R version 3.3.2)
Can anyone please help me how and where I can download the package?
First, that does not sound like an R-package, but rather like an outdated utility program for GAMS.
I say outdated, because GAMS now has built-in the functionality to convert GDX (GAMS data files) to CSV files, which can be read by any statistics program including R.
GAMS also gives you the option of exporting your data to an SQLite database file (.db), which can be read by R.
Have a look here:
https://www.gams.com/help/index.jsp?topic=%2Fgams.doc%2Fuserguides%2Fmccarl%2Fgdx_utilities.htm
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
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