Displaying 20 results from an estimated 20000 matches similar to: "R errors when trying to read a file"
2008 Jun 09
2
readLines fails to read entire file
Colleagues
I have just encountered an interesting problem with readLines in R
2.7.0 in Windows Vista. I am trying to read a line that is created in
the following manner:
1. Intel Fortran (ifort) 10.1 creates two text files.
2. The OS concatenates these files with: copy FILE1 +FILE2 FILE3
From R, I execute: readLines("FILE3")
Only the first portion of the file (the original
2010 Feb 12
1
Identifying special characters in a text file
Colleagues
R 2.10.1 on a Mac
I read in textfiles using readLines, then I process those files, then I use R to execute another program. Occasionally those files contain characters other than letter / numbers / routine punctuation marks. For example, a bullet (option-8 on a Mac) triggers the problem.
Although R can read and process those characters, the other program cannot so I would like to
2008 Oct 12
2
proper use of textConnection
Colleagues,
Using R2.7.0 in OS X, I am having trouble understanding the command
textConnection. My situation is as follows:
1. I am trying to read a lengthy file (45000 lines) that has headers
~ every 1000 lines. read.table (or its variants) fail because of the
recurrent headers.
2. My present approach is the following:
a. use readLines to read the file, save as an array
b. use grep
2008 Sep 17
1
Dealing with missing EOL at end of file
Colleagues,
I am using R 2.7.2 on all three platforms (OS X; Windows; Linux) and I
have encountered the following problem:
I use R to issue a system call the execute a command in the OS. For
example:
system("DOSOMETHING TOSOMEFILE")
In most situations, this task completes successfully and control
returns to R. However, in rare situations, the target file
(TOSOMEFILE) is
2011 Dec 31
2
read.csv error: invalid multibyte string
R version: 2.13.1
OS X
Colleagues,
I am working with a CSV file; for testing purposes, I created an XLS version of the file.
When I read these files using read.xls (gdata) or read.csv, I encounter an error:
Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, na.strings = character(0L)) :
invalid multibyte string at '<b0>C'
The error occurs whether or not I invoke
2010 Oct 11
1
grep triggering error on unicode character
Colleagues,
[R 2.11; OS X]
I am processing a file on the fly that contains the following text:
XXX??
[email clients may display this differently -- the string is three X's followed by two instances of the letter a with an acute accent]
I read the file with:
X <- readLines(FILENAME)
In this instance, the text of interest is on line 213. When I examine line 213, it reads:
XXX\xe1\xe1
2010 May 16
1
Reading JPEG file, converting to HEX
Colleagues,
I am using R to assemble RTF documents (which are plain text). I need to embed a JPEG graphic that was created with R. I presume that the steps need to be:
a. read the file into R
b. convert the object to HEX format
c. write the converted object to a textfile.
If I read the file into R using readLines, I get the following (only the first 5 lines shown):
> >
2009 Sep 29
3
Deleting a column in a dataframe by name
Colleagues,
Hopefully a simple problem: I want to delete a column with a known
name from a dataframe. I could write:
FRAME <- FRAME[, names(FRAME) != NAMETODELETE]
or
FRAME <- FRAME[, !names(FRAME) %in% c(NAME1, NAME2, ETC)]
Is there some simpler means to accomplish this?
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
2007 Sep 04
2
Recursive concatenation
Colleagues,
I want to create the following array:
"A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"
I recall that there is a trick using "c" or "paste" permitting me to
form all combinations of c("A", "B", "C") and 1:3. But, I can't
recall the
2008 Dec 15
3
opening a PDF document
Colleagues,
I am interesting in opening a PDF document via the command line from
both Windows, OS X, and Linux ( R version 2.8.0). I found a command
openPDF in Biobase. However, I would rather execute the command
myself. For example, in OS X:
> system("open filename.pdf")
is successful.
Is there a comparable command line command for Windows or Linux?
Dennis
Dennis Fisher
2008 Apr 11
3
strsplit and sapply
Colleagues,
I have some text:
TEXT <- c("a", "bb;ccc", "dddd;eeeee;ffffff")
I want to retrieve the portion of each element before the first
semicolon. I can split each element using strsplit:
SPLIT <- strsplit(TEXT, ";")
This yields:
> SPLIT
[[1]]
[1] "a"
[[2]]
[1] "bb" "ccc"
[[3]]
[1] "dddd"
2005 Oct 18
6
Subsetting a list
Colleagues,
I have created a list in the following manner:
TEST <- list(c("A1", "A2"), c("B1", "B2"), c("C1", "C2"))
I now want to delete one element from the list, e.g., the third. The
command
TEST[[3]]
yields (as expected):
[1] "C1" "C2"
The command
TEST[[-3]]
yields:
Error:
2012 Oct 18
4
speeding read.table
R 2.15.1
OS X
Colleagues,
I am reading a 1 GB file into R using read.table. The file consists of 100 tables, each of which is headed by two lines of characters.
The first of these lines is:
TABLE NO. 1
The second is a list of column headers.
For example:
TABLE NO. 1
COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10
2005 Jul 22
3
Question regarding subsetting
I run R 2.1.1 in a Linux environment (RedHat 9) although my question
is not platform-specific.
Consider the following:
> A <- c("Prefix-aaa", "Prefix-bbb", "Prefix-ccc")
> B <- strsplit(A, "-")
> B
[[1]]
[1] "Prefix" "aaa"
[[2]]
[1] "Prefix" "bbb"
[[3]]
[1] "Prefix" "ccc"
How
2006 Oct 21
2
Filling in a series
Colleagues
After reading in some clinical data, I discovered that the subject ID
column contains entries only for the first record for each
individual; subsequent rows are recorded as NA. For example:
> 1
> NA
> NA
> NA
> NA
> 2
> NA
> NA
> NA
> NA
> 3
> NA
> NA
> ...
I can think of various approaches to replace the NA values with
appropriate
2007 Aug 03
3
Sourcing commands but delaying their execution
Colleagues:
I have encountered the following situation:
SERIES OF COMMANDS
source("File1")
MORE COMMANDS
source("File2")
Optimally, I would like File1 and File2 to be merged into a single
file (FileMerged). However, if I wrote the following:
SERIES OF COMMANDS
source("FileMerged")
MORE COMMANDS
I encounter an error: the File2 portion of FileMerged
2011 Aug 10
1
Reading XML files masquerading as XL files
R version 2.13.1
OS X (or Windows)
Colleagues,
I received a number of files with a .xls extension. These files open in XL and, by all appearances, are XL files. However, it appears to me that the files are actually XML:
> readLines(dir()[16])[1:10]
[1] "<?xml version=\"1.0\"?>"
[2] "<Workbook
2009 Jan 30
3
identifying what labels have been created in a plot
Colleagues
R 2.8.0; OS X, Vista, Ubuntu Linux
In some instances, when I create a graphic using plot(XVAR, YVAR), it
would be valuable to know the values that R will display on the y-axis
(e.g., if the range of data is 0-70, it might display 0, 10, 30, 50,
70). Is there a simple means to access these values?
Also, in some instances, additional ticks appear between the displayed
values
2009 Sep 23
2
Updating R for Linux
Colleagues,
Please forgive my ignorance of this topic. I am experienced with the
installation/use of R in OSX and Windows, much less so with Linux.
I just created a virtual machine of Ubuntu 9.0.4. Using the Synaptic
Package Manager, I installed R 2.8.1. I would like to obtain 2.9.x
and I am having trouble doing so using the tools available within
Ubuntu.
I tried
apt-get install
2005 Jan 17
2
Question about time series
I have data in the following format:
> DATE
[1] "01/13/2004"
In order to find the difference between two data points, I presently
use brute force to calculate the day of the year:
> strptime(DATE, format="%m/%d/%Y")$yday
[1] 12
Although this works, it may not be robust over different years. I
assume that R is sufficiently clever that a much simpler approach