Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:28:14+00:00 2026-05-27T01:28:14+00:00

The problem I have a tab delimited input file that looks like so: Variable

  • 0

The problem

I have a tab delimited input file that looks like so:

Variable [1]    Variable [2]
111    Something
Nothing    222

The first row represents column names and the two next rows represents column values. As you can see, the column names includes both spaces and some tricky signs.

Now, what I want to do is to import this file into R and then output it again to a new text file, making it look exactly the same as the input. For this purpose I have created the following script (assuming that the input file is called “Test.txt”):

file <- "Test.txt"
x <- read.table(file, header = TRUE, sep = "\t")
write.table(x, file = "TestOutput.txt", sep = "\t", col.names = TRUE, row.names = FALSE)

From this, I get an output that looks like this:

"Variable..1."  "Variable..2."
"1"    "111"    "Something"
"2"    "Nothing"    "222"

Now, there are a couple of problems with this output.

  1. The “[” and “]” signs have been converted to dots.
  2. The spaces have been converted to dots.
  3. Quote signs have appeared everywhere.

How can I make the output file look exactly the same as the input file?

What I’ve tried so far

Regarding problem number one and two, I’ve tried specifying the column names through creating an internal vector, c("Variable [1]", "Variable [2]"), and then using the col.names option for read.table(). This gives me the exact same output. I’ve also tried different encodings, through the encoding option for table.read(). If I look at the internally created vector, mentioned above, it prints the variable names as they should be printed so I guess there is a problem with the conversion between the “text -> R” and the “R -> text” phases of the process. That is, if I look at the data frame created by read.table() without any internally created vectors, the column names are wrong.

As for problem number three, I’m pretty much lost and haven’t been able to figure out what I should try.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:28:15+00:00Added an answer on May 27, 2026 at 1:28 am

    Given the following input file as test.txt:

    Variable [1]    Variable [2]
    111 Something
    Nothing 222
    

    Where the columns are tab-separated you can use the following code to create an exact copy:

    a <- read.table(file='test.txt', check.names=F, sep='\t', header=T, 
        stringsAsFactors=F)
    write.table(x=a, file='test_copy.txt', quote=F, row.names=F, 
        col.names=T, sep='\t')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tab-delimited text file that I am parsing. Its first column contains
I have a problem using data from a tab delimited data file imported with
I have a tab delimited text file with the first row being label headings
I have a problem with reading a tab delimited file. The structure on my
So I have this small xls file that's actually a tab-delimited txt file. In
I have got string containing windows path to file. It looks something like this:
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
My problem is that I want to have a tab bar view with its
I have a Tab-delimited String (representing a table) that is passed to my method.
I receive a tab-delimited text file that must be parsed. Once parsed, the parts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.