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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:44:35+00:00 2026-05-28T00:44:35+00:00

I would like to ask if there is a way to align text after

  • 0

I would like to ask if there is a way to align text after we have entered it in gtext.
For example

x <- c(123.4, 5.6)
y <- c(1.2, 3.657)
z <- c(12345.6, 789.4)

df <- data.frame(x, y, z)

df.co <- capture.output(df) # get df as text

for (i in 1:length(df.co))
{
    str.split <- strsplit(df.co, "\\s+") # split every line in its components
}

w3 <- gwindow()
gt3 <- gtext(container=w3)

for (i in 1:length(str.split)) # length(str.split)=3
{
for (j in 1:length(str.split[[i]])) # length(str.split[[i]])=2
    {
        str.split[[i]][[j]] <- paste(str.split[[i]][[j]],"\t",sep="",collapse="")  # add tab to each component
    }
    str.split[[i]] <- paste(str.split[[i]], sep="", collapse="") # join to one line
    insert(gt3, str.split[[i]])
}

This way we mimic the R console.
Thank you a lot, in advance

  • 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-28T00:44:35+00:00Added an answer on May 28, 2026 at 12:44 am

    There is no way to align text in the sense of right-align/centre/etc in gWidgets.

    I recommend monospace fonts as @Dason suggested (although that seems to be the default for me).

    In terms of your code, you can clean it up a little:

    • You don’t need the loop in creation of str.split (nothing depends on
      i and you are writing over str.split each time)
    • You can eliminate the loops that you use to put the tabs in str.split[[i]]
    • You don’t need to add each line of str.split in separately, you can do it all at once.

    In summary:

    x <- c(123.4, 5.6)
    y <- c(1.2, 3.657)
    z <- c(12345.6, 789.4)
    
    df <- data.frame(x, y, z)
    
    df.co <- capture.output(df) # get df as text
    
    # @@ don't need loop
    str.split <- strsplit(df.co, "\\s+") # split every line in its components
    
    w3 <- gwindow()
    gt3 <- gtext(container=w3)
    
    # @@ collapse each str.split[[i]] by joining with '\t'.
    str.joined <- sapply(str.split,function(bits) paste(bits,collapse='\t'))
    insert(gt3,str.joined)
    

    Alternately, you can replace everything after df.co <- capture.output(df) by:

    insert(gt3,df.co)
    

    (do the two side-by-side and compare: insert(gt3,df.co) right-aligns each column of the dataframe, exactly as typing df would show; the method you have (insert(gt3,str.joined)) left-aligns each column.

    # insert(gt3,str.joined)/method in your question
        x       y       z   
    1   123.4   1.200   12345.6
    2   5.6     3.657   789.4
    
    # insert(gt3,df.co)
          x     y       z
    1 123.4 1.200 12345.6
    2   5.6 3.657   789.4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like ask if there's a way to download an android layout from
I would like to ask is there any way to achieve this functionality: I
I would like to ask if there is a way to see a variable
I would like to ask if there is a more elegant way to write
I would like to ask if there is a more elegant way to insert
I would like to ask if there is a possible way to select all
I would Like to ask you, if there is a way to set some
I would like to ask you whether there exists a way to automate reverse-engineering
community! I would like to ask if there is any easy way to determine
I would just like to ask, is there a way to possibly customize the

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.