Displaying 20 results from an estimated 20000 matches similar to: "Appending strings at the beginning of a text file"
2009 Jan 23
2
Write to multiple connections or multiple text files
Hi all,
I want to modify a large number of text files (ca 4000) by replacing a
value found on a particular line in them with a value from an R object.
For a single file I would normally use:
con<-file ("foo.txt", open="r+")
content<-readLines(con)
content[n]<-"test"
writeLines(content,con)
close(con)
For repeating this for several files I can
2010 Apr 15
3
Add header line to large text file
All,
I have a 30 million record text file without header information. I would
like to add a header to this file without reading it first. Is this
possible? The code below does what I want except that the readLines
portion takes quite a long time. Is there a way around reading the
lines? I'm working on Windows XP.
Zev
input<-readLines("c:/junk/forR.csv")
2008 Oct 27
1
replace a few strings in a text file
Dear all,
I wrote a wrapper to a FORTRAN program using R. The main program uses
a text file (~200 lines) as an input describing the simulation to be
run. I typically generate the file once with the right parameters
using a combination of file(), paste(), cat(). This is fine, and it
works well, however I then need to update only a few values in the
file many times (~200 times,
2010 Dec 17
4
Changing a value in a particular row and column within a text file
Dear list,
I need to change a value within a particular line of a plain text file
with characters and numbers, and I haven't found any way of doing this
by using R.
What I have a is a file that doesn't have tabular data (so, I think
that 'read.table' or 'read.delim' are not the right tools for this),
but some text, and I now exactly the row that has to be modified and
the
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
2010 Sep 12
4
using read.table, removing extra quotation mark from a text field? (e.g. ""cat" )
I am using read.table to import a text file within R.
There are several "errors" in my text file. An "extra" quotation mark has
inadvertently been included within a few text fields.
e.g. for a pipe (|) delimited text file, I have something similar to this:
1|7|30| "dog"
2|6|25| ""cat"
3|4|20|""
4|5| 56| "mouse"
5|3|56|
2013 Apr 10
1
Issue with Control-Z in a text file on Windows - readLines() appears to truncate
Working on Windows I have had to deal with CSV files that,
unfortunately, contain embedded Control-Zs, i.e. ASCII character 26 in
decimal, and the readLines() function in R on Windows (2.15.2 and
3.0.0) appears to truncate at the control-Z. There is no problem at
all on Ubuntu Linux with R 3.0.0.
Am I mistaken or is this genuine?
# Create a small file with embedded Control-Z
h3 <-
2003 Oct 02
1
Search for a text string and write position related data to a file
Dear all,
I just started using R today. What I need to do is find a text string in a (large) text file and than copy the some position related lines (or text) to an other text file. Is this possible with R?
Example: Search string is: "Date"
write line of <search string> +0, +2, +6, +7, +8, +9
########################################
1 Report of measured data
2 -
3 Date: 01-10-03
2005 May 28
1
(PR#7899) seek(con, 0, "end", rw="r") does not always work
Tony Plate wrote:
> ligges@statistik.uni-dortmund.de wrote:
>
>> tplate@blackmesacapital.com wrote:
>>
>>
>>> I've noticed that seek(con, 0, "end", rw="r") on a file connection
>>> does not always work correctly after a write (R 2.1.0 on Windows).
>>>
>>> [Is a call to fflush() needed inside file_seek() in
2010 Oct 26
3
stripping #s in a text file prior to reading into table or dataframe
I'm importing a lot of text tables of data (from Latent Gold) that includes
hashes in some of the column names ("Cluster#1", "Cluster#2", etc.). Is
there an easy way to strip the offending hashes out before pushing the text
into a table or data frame? I thought I'd use gsub, e.g., but can't figure
out how to read in a text file without reading it into a table or
2016 Feb 25
2
iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param)
On 23.02.2016 14:06, Mikko Korpela wrote:
> On 23.02.2016 11:37, Martin Maechler wrote:
>>>>>>> nospam at altfeld-im de <nospam at altfeld-im.de>
>>>>>>> on Mon, 22 Feb 2016 18:45:59 +0100 writes:
>>
>> > Dear R developers
>> > I think I have found a bug that can be reproduced with two lines of code
>>
2010 May 05
2
readLines with space-delimiter?
Hi,
I am reading a large space-delimited text file into R (41 columns and many
rows) and need to do run each row's values through another R object and then
write to another text file. So, far using readLines and writeLines seems to
be the best bet. I've gotten the data exchange working except each row is
read in as one 'chunk', meaning the row has all values between two quotes
2011 Apr 22
2
writing/appending a text file
Hello
I'm fairly new to R. I have a script which produces a 1-column vector
(numeric). I can write it to a text file using the write command. What I
want to do is to run the script a number of times on different input files,
producing a different 1-column vector each time and save all the vectors to
a text file so that each vector is one separate column in the text file. I
had thought of
2004 Jul 26
6
directing print.packageInfo to a file
There was a discussion on r-help of getting the output from
print.packageInfo into a file. Spencer and I have added a file=
argument to print.packageInfo for consideration in R. Had this
been available it would have simplified the answer to that
thread. If the file= argument is used then the packageInfo
information is sent to the file specified rather than displayed
using file.show .
2014 Oct 19
1
Writing UTF8 on Windows
Recent functionality in jsonlite allows for streaming json to a user
supplied connection object, such as a file, pipe or socket. RFC7159
prescribes json must be encoded as unicode; ISO-8859 (including
latin1) is invalid. Hence I would like R to write strings as utf8,
irrespective of the type of connection, platform or locale.
Implementing this turns out to be unsurprisingly difficult on windows.
2008 Sep 01
3
how to read multiple lines per case
How can I read a space-delimited file, where the data values for each case
are folded before column 80, and so appear on two lines for each case?
The first few cases look like this
loc type bio H2S sal Eh7 pH buf P K Ca Mg Na Mn Zn Cu NH4
OI DVEG 676 -610 33 -290 5.00 2.34 20.238 1441.67 2150.00 5169.05 35184.5
14.2857 16.4524 5.02381 59.524
OI DVEG 516 -570 35 -268 4.75 2.66 15.591 1299.19
2017 Dec 29
3
Writing text files out of a dataset
Hello,
I am trying to run the following syntax for all cases within the dataframe
"data"
d1 <- data[1,c("material")]
fileConn<-file("TESTI/d1.txt")
writeLines(d1, fileConn)
close(fileConn)
I am trying to use the for function:
for (i in 1:nrow(data)){
d[i] <- data[i,c("material")]
fileConn<-file("TESTI/d[i].txt")
2013 Jul 02
3
Ctrl+C in R will terminate the child process which is spawned by using "pipe"
Hi, all,
I pressed Ctrl+C in R process, and found that the child process which was
spawned by using "pipe" is terminated due to this.
Are there any way to work around it, so that the child process can run
happily without being terminated? Or can we block the signal for the child
process?
1. I used pipe to spawn one C++ process, which will running in a loop
without exiting immediately.
2016 Feb 23
4
iconv to UTF-16 encoding produces error due to embedded nulls (write.table with fileEncoding param)
>>>>> nospam at altfeld-im de <nospam at altfeld-im.de>
>>>>> on Mon, 22 Feb 2016 18:45:59 +0100 writes:
> Dear R developers
> I think I have found a bug that can be reproduced with two lines of code
> and I am very thankful to get your first assessment or feed-back on my
> report.
> If this is the wrong mailing list or I
2017 Aug 19
2
Update data in text file with data in dataframe
Hello all,
I'm a novice R programmer and I don't have a clue as to how to approach
this. I have tried many different approaches only to fail and I can't
seem to wrap my head around it. So I turn to the experts.
I have a text file with patient data that has incorrect dates of
service. I need to update the dates of service in the text file with
data that's in a dataframe.