unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Markus Triska <triska@gmx.at>
Subject: Re: Importing tab-delimited text files or connecting to ODBC
Date: Fri, 17 Feb 2006 00:33:45 +0100	[thread overview]
Message-ID: <43f50bd4$0$12642$3b214f66@tunews.univie.ac.at> (raw)
In-Reply-To: <uvevf4rrv.fsf@snt.si>

Hi!

Maks Romih wrote:

> What would be the best way to import some tables, like a tab delimited
> copy-paste chunk from excel. I would like to get the table into Emacs
> Lisp so that a table would be a big list of rows, where a row would be
> a list of atoms, either raw strings or, when possible, converted to
> Lisp numbers and symbols.

You can use R (www.r-project.org) to handle a number of different table 
formats uniformly. For example, given test.txt like this:

# directory size unit
/home/tester1 200 MB
/home/tester2 3000 KB
/home/tester3 250 MB

you can read it as a data frame:

 > data <- read.table("test.txt", as.is=c(T,F,T), skip=1)

You then use a function like this to print it the way you want:

elisp <- function (df) {
         cat("(")
         for (i in 1:(dim(df)[1])) {
                 cat("\n(")
                 for (j in 1:dim(df)[2]) {
                         val <- df[i,j]
                         if (is.numeric(val)) {
                                 cat(" ", val, " ", sep="")
                         } else {
                                 cat(" \"", val, "\" ", sep="")
                         }
                 }
                 cat(")\n")
         }
         cat(")\n")
}


 > elisp(data)
(
( "/home/tester1"  200  "MB" )

( "/home/tester2"  3000  "KB" )

( "/home/tester3"  250  "MB" )
)

These steps can be automated using R's batch facilities that you can 
call from Emacs. Some of the other conversions you mention can probably 
also be handled more directly in the R code.

All the best,
Markus.

  reply	other threads:[~2006-02-16 23:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-16  8:44 Importing tab-delimited text files or connecting to ODBC Maks Romih
2006-02-16 23:33 ` Markus Triska [this message]
2006-02-17 12:19   ` Maks Romih
2006-02-17  0:04 ` Thien-Thi Nguyen
2006-02-17 14:29   ` Maks Romih
2006-02-17 16:35     ` Eric Pement
2006-02-17 17:01       ` Maks Romih
2006-02-17 19:06         ` Tim McNamara
2006-02-18 18:25           ` Peter S Galbraith
2006-02-18  5:53     ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='43f50bd4$0$12642$3b214f66@tunews.univie.ac.at' \
    --to=triska@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).