+ Reply to Thread
Results 1 to 4 of 4

Thread: Maybe this not need escaped "\b"

  1. #1
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Maybe this not need escaped "\b"




    This code looks like this if I cat it to the console:

    Code: 
    list(
        transcript_time_span = c(00:00 - 00:00),
        A = c(),
        B = c(),
        C = c() 
    )
    But prints a weird character for "\b" depending on the text editor. I want to get rid of the "\b" but still have it print appropriately to a file regardless of what codes is.

    Code: 
    file <- "foo.txt"
    codes <- LETTERS[1:3] 
    #codes <- LETTERS[1:6]   #(codes could be this too)
    #codes <- 1:9 or this    #(or this)
    
    cat(paste("list(\n",
        "   transcript_time_span = c(00:00 - 00:00),\n",
        paste0("    ", paste0("\b", paste(codes, 
            collapse = " = c(),\n    "), " = c()")), "\n)\n"),
    file=file, append = TRUE)
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  2. #2
    Devorador de queso
    Points: 95,540, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent Poster
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,930
    Thanks
    307
    Thanked 2,629 Times in 2,245 Posts

    Re: Maybe this not need escaped "\b"

    The best thing to do is get rid of the \b. This is easily accomplished by just using paste0 in place of the first paste.

    Code: 
    cat(paste0("list(\n",
        "    transcript_time_span = c(00:00 - 00:00),\n",
        paste0("    ", paste0(paste(codes, 
            collapse = " = c(),\n    "), " = c()")), "\n)\n"),
        append = TRUE)
    I don't have emotions and sometimes that makes me very sad.

  3. The Following User Says Thank You to Dason For This Useful Post:

    trinker (10-17-2012)

  4. #3
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: Maybe this not need escaped "\b"

    I hate you and love you all at the same time. Thanks Dason.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  5. #4
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Re: Maybe this not need escaped "\b"


    The output. May look boring to you but to me a thing of beauty:

    Code: 
    [0]                                                                                30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [1]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [2]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [3]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [4]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [5]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [6]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    [7]0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                                                         
    
    
    list(
        transcript_time_span = c(00:00 - 00:00),
        AA = c(),
        BB = c(),
        CC = c()
    )
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

+ Reply to Thread

           




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats