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 7171121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:21:00+00:00 2026-05-28T15:21:00+00:00

This question is almost the same as a previous question , but differs enough

  • 0

This question is almost the same as a previous question, but differs enough that the answers for that question don’t work here. Like @chase in the last question, I want to write out multiple files for each split of a dataframe in the following format(custom fasta).

#same df as last question

df <- data.frame(
    var1 = sample(1:10, 6, replace = TRUE)
    , var2 = sample(LETTERS[1:2], 6, replace = TRUE)
    , theday = c(1,1,2,2,3,3)
)    

#how I want the data to look
write(paste(">", df$var1,"_", df$var2, "\n", df$theday, sep=""), file="test.txt")

#whole df output looks like this:
#test.txt
>1_A 
1
>8_A
1
>4_A 
2
>9_A 
2
>2_A 
3
>1_A 
3

However, instead of getting the output from the entire dataframe I want to generate individual files for each subset of data. Using d_ply as follows:

d_ply(df, .(theday), function(x) write(paste(">", df$var1,"_", df$var2, "\n", df$theday, sep=""), file=paste(x$theday,".fasta",sep="")))

I get the following output error:

Error in file(file, ifelse(append, "a", "w")) : 
  invalid 'description' argument
In addition: Warning messages:
1: In if (file == "") file <- stdout() else if (substring(file, 1L,  :
  the condition has length > 1 and only the first element will be used
2: In if (substring(file, 1L, 1L) == "|") { :
  the condition has length > 1 and only the first element will be used

Any suggestions on how to get around this?

Thanks,
zachcp

  • 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-28T15:21:01+00:00Added an answer on May 28, 2026 at 3:21 pm

    There were two problems with your code.

    • First, in constructing the file name, you passed the vector x$theday to paste(). Since x$theday is taken from a column of a data.frame, it often has more than one element. The error you saw was write() complaining when you passed several file names to its file= argument. Using instead unique(x$theday) ensures that you will only ever paste together a single file name rather than possibly more than one.

    • Second, you didn’t get far enough to see it, but you probably want to write the contents of x (the current subset of the data.frame), rather than the entire contents of df to each file.

    Here is the corrected code, which appears to work just fine.

    d_ply(df, .(theday), 
        function(x) {write(paste(">", x$var1,"_", x$var2, "\n", x$theday, sep=""), 
                           file=paste(unique(x$theday),".fasta",sep=""))
        })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Almost the same question as this one here: What's the easiest way to grab
In reference to this question, I am facing almost the same scenario except that
My question is almost exactly the same as this post , except that I'm
I am almost embarrassed to ask this question, but as a long time C
I'm almost certain I know the answer to this question, but I'm hoping there's
This is almost certainly a very silly question, but for some reason I'm having
I don't know if this is a dumb question but I have this two
This question is geared towards MySQL, since that is what I'm using -- but
This is almost exactly the same as this question json get key names as
I have almost the same problem as this unanswered question . The only difference

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.