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

  • SEARCH
  • Home
  • 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 9074577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:40:10+00:00 2026-06-16T18:40:10+00:00

I have written a function that allows me to take four columns of data

  • 0

I have written a function that allows me to take four columns of data from the clipboard, split it, add an extra column, recombine it, and export it as a text file.

xyztoinp <- function(x) {
    x <- read.table(file="clipboard") 
    a <- x[,-1] 
    b <- x[,1]
    c <- ifelse(b == "C", 6,
    ifelse (b == "O", 8,ifelse (b == "H", 1, 3)))
    x <- cbind(b,c,a)
    write.table(x, file="IRCoutput", quote = FALSE,
    sep = "\t", row.names = FALSE, col.names = FALSE)
}

I have two questions:-

Is it possible to create a file that has the table that I’ve created with this function such that the table is pasted into the middle of some text?

Eg

text_text_text_text_text_text_text_
text_text_text_text_text_text_text_

Neatly formated table

text_text_text_text_text_text_text_
text_text_text_text_text_text_text_

Secondly, I tried to modify the function so that it would take a file name as a variable; ie, xyztoinp <- function(x, NewFileName) {

etc…
But this didn’t produce an output with the new file name; does anyone know how this is done?

Here is my working code,

xyztoinp <- function(x) {
     x <- read.table(file=”clipboard”)
     a <- x[,-1]
     b <- x[,1]
     c <- ifelse(b == “C”, 6,
     ifelse (b == “O”, 8,
     ifelse (b == “H”, 1, 3)))
     x <- cbind(b,c,a)
     zz <- file(“NewFile.inp”, “w”)
     cat(“text”,
     ” text”,
     “text”,
     “”,
     “text”,
     “text”,
     “text”, file = zz, sep = “\n”)
     write.table(x, file=zz, quote = FALSE,
     sep = “\t”, row.names = FALSE, col.names = FALSE)
     cat(“text”,file=zz)
     close(zz)
}

thanks all, esp @Greg.
ps It wasn’t possible to vary the filename in the function but I’m happy with the above.

  • 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-06-16T18:40:11+00:00Added an answer on June 16, 2026 at 6:40 pm

    The general reason why people want tables (or graphs, or output, or …) insterted into text is to create an automatic report of some sort (if this is not your case then please give more detail so we can answer the actual question).

    To create automated reports with nicely formated tables (and other things) the best approach is to create a template and process it to create the report. Look at the knitr package for details on doing this (you can also use the odfweave package or the sweave function or others, but knitr is probably the most general).

    Another option if you don’t want to precreate the report template is the pander package.

    Switching to pander or knitr may take care of your second question as well, but if not then we will need to see what you tried and what happened to know why it did not work and how to help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function that sorts a big scale of data. To test
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
I have written code to perform a function that could take a while to
I have written a PHP function to take a video embed code that has
I have a function written in javascript that allows me to scroll through an
I have written a private function that allows me to call the name of
I have written a function in my program that allows me to retrieve strings
I have written a function that positions a tooltip just above a textbox. The
I have written a javascript function that uses setInterval to manipulate a string every
I currently have a function written called saveWorkout that saves an NSMutableArray to another

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.