all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [babel] Idiomatic handling of quotes
@ 2009-12-17 20:15 Thomas S. Dye
       [not found] ` <D66D7851-44D9-490A-8EA5-271BFE96FEEB-P0awH739Ni4AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas S. Dye @ 2009-12-17 20:15 UTC (permalink / raw)
  To: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 1177 bytes --]

Aloha all,

In the example below, note that the R representation of the directory  
listing escapes the quotes in the original and encloses it all in a  
second set of quotes, e.g. "\"theta-1.csv\"".

This must come up a lot.  Is there an idiomatic way to change  
"\"theta-1.csv\"" to "theta-1.csv" so that it could be assigned to x  
and the following statement would yield a valid path?

afile <- paste("r/",x,sep="")

I'm aware the answer might be R code, but it is to tightly tied to org- 
babel I figure it makes sense to ask the question here.

All the best,
Tom

--------------- Example -------------------
*** Dated events
#+srcname: thetas()
#+begin_src shell
cd r && ls theta*
#+end_src

#+results: thetas
| "theta-1.csv" |
| "theta-2.csv" |
...

#+srcname: test-list(x = thetas)
#+begin_src R :session
   str(x)
   x
#+end_src

#+results: test-list
| "theta-1.csv" |
| "theta-2.csv" |
...

tdye> str(x)
'data.frame':	8 obs. of  1 variable:
  $ V1: chr  "\"theta-1.csv\"" "\"theta-2.csv\"" "\"theta-3.csv\""  
"\"theta-4.csv\"" ...



Thomas S. Dye, Ph.D.
T. S. Dye & Colleagues, Archaeologists, Inc.
Phone: (808) 529-0866 Fax: (808) 529-0884
http://www.tsdye.com



[-- Attachment #1.2: Type: text/html, Size: 4212 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [babel] Idiomatic handling of quotes
       [not found] ` <D66D7851-44D9-490A-8EA5-271BFE96FEEB-P0awH739Ni4AvxtiuMwx3w@public.gmane.org>
@ 2009-12-18  9:20   ` Francesco Pizzolante
  2009-12-18 18:22     ` Thomas S. Dye
  0 siblings, 1 reply; 3+ messages in thread
From: Francesco Pizzolante @ 2009-12-18  9:20 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Org Mode

Hi Thomas,

> In the example below, note that the R representation of the directory listing
> escapes the quotes in the original and encloses it all in a  second set of
> quotes, e.g. "\"theta-1.csv\"".
>
> This must come up a lot.  Is there an idiomatic way to change
> "\"theta-1.csv\"" to "theta-1.csv" so that it could be assigned to x  and the
> following statement would yield a valid path?
>
> afile <- paste("r/",x,sep="")
>
> I'm aware the answer might be R code, but it is to tightly tied to org-
> babel I figure it makes sense to ask the question here.

I already sent an email related to double quotes in result tables. See the
email hereunder.

In order to get a result table without the double quotes for all texts, I use
the patch enclosed in my email and add the ":results noquotes" header
parameter.

In your example, I would get the following result:

--8<---------------cut here---------------start------------->8---
#+srcname: thetas()
#+begin_src shell :results noquotes
cd r && ls theta*
#+end_src

#+results: thetas
| theta-1.csv   |
| theta-2.csv   |
--8<---------------cut here---------------end--------------->8---

Is this what you need?

Here's the email I sent a few days ago. It contains the patch I use to remove
the double quotes when I need it:

-----------------------------------------------------------------
From: Francesco Pizzolante <fpz-djc/iPCCuDYQheJpep6IedvLeJWuRmrY@public.gmane.org>
Subject: [Orgmode] [babel] double quotes in tables
To: mailing-list-org-mode <emacs-orgmode-mXXj517/zsQ@public.gmane.org>
Date: Mon, 14 Dec 2009 17:18:30 +0100

Hi,

Often, I find useful that babel could generate result tables without the
double quotes (") enclosing all the text values in the cells.

In order to do that, I added a 'noquotes` option to the :results header
argument.

Here's my patch. As I'm not an elisp expert, please tell me if there's a
better/safer way to do that or maybe that it already exists an option to do
that...

--8<---------------cut here---------------start------------->8---
diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el
index 4c9bff5..13c8237 100644
--- a/contrib/babel/lisp/org-babel.el
+++ b/contrib/babel/lisp/org-babel.el
@@ -706,6 +706,9 @@ code ---- the results are extracted in the syntax of the source
           code of the language being evaluated and are added
           inside of a #+BEGIN_SRC block with the source-code
           language set appropriately."
+  (setq outputformat "%S")
+  (if (member "noquotes" result-params)
+      (setq outputformat "%s"))
   (if (stringp result)
       (progn
         (setq result (org-babel-clean-text-properties result))
@@ -739,7 +742,7 @@ code ---- the results are extracted in the syntax of the source
 			     (if (and (listp (car result))
                                       (listp (cdr (car result))))
 				 result (list result))
-			     '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
+			     '(:fmt (lambda (cell) (format outputformat cell)))) "\n"))
 	    (forward-line -1) (org-cycle))
 	   ((member "file" result-params)
 	    (insert result))
@@ -827,7 +830,8 @@ parameters when merging lists."
   (let ((results-exclusive-groups
 	 '(("file" "vector" "table" "scalar" "raw" "org" "html" "latex" "code" "pp")
 	   ("replace" "silent")
-	   ("output" "value")))
+	   ("output" "value")
+           ("noquotes")))
 	(exports-exclusive-groups
 	 '(("code" "results" "both" "none")))
 	params results exports tangle cache vars var ref)
--8<---------------cut here---------------end--------------->8---

Thanks,
Francesco
-----------------------------------------------------------------

Regards,
Francesco




_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [babel] Idiomatic handling of quotes
  2009-12-18  9:20   ` Francesco Pizzolante
@ 2009-12-18 18:22     ` Thomas S. Dye
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas S. Dye @ 2009-12-18 18:22 UTC (permalink / raw)
  To: Francesco Pizzolante; +Cc: Org Mode

Hi Francesco,

On Dec 17, 2009, at 11:20 PM, Francesco Pizzolante wrote:

> Hi Thomas,
>
>> In the example below, note that the R representation of the  
>> directory listing
>> escapes the quotes in the original and encloses it all in a  second  
>> set of
>> quotes, e.g. "\"theta-1.csv\"".
>>
>> This must come up a lot.  Is there an idiomatic way to change
>> "\"theta-1.csv\"" to "theta-1.csv" so that it could be assigned to  
>> x  and the
>> following statement would yield a valid path?
>>
>> afile <- paste("r/",x,sep="")
>>
>> I'm aware the answer might be R code, but it is to tightly tied to  
>> org-
>> babel I figure it makes sense to ask the question here.
>
> I already sent an email related to double quotes in result tables.  
> See the
> email hereunder.
>
> In order to get a result table without the double quotes for all  
> texts, I use
> the patch enclosed in my email and add the ":results noquotes" header
> parameter.
>
> In your example, I would get the following result:
>
> --8<---------------cut here---------------start------------->8---
> #+srcname: thetas()
> #+begin_src shell :results noquotes
> cd r && ls theta*
> #+end_src
>
> #+results: thetas
> | theta-1.csv   |
> | theta-2.csv   |
> --8<---------------cut here---------------end--------------->8---
>
> Is this what you need?
>
> Here's the email I sent a few days ago. It contains the patch I use  
> to remove
> the double quotes when I need it:
>
> -----------------------------------------------------------------
> From: Francesco Pizzolante <fpz@missioncriticalit.com>
> Subject: [Orgmode] [babel] double quotes in tables
> To: mailing-list-org-mode <emacs-orgmode@gnu.org>
> Date: Mon, 14 Dec 2009 17:18:30 +0100
>
> Hi,
>
> Often, I find useful that babel could generate result tables without  
> the
> double quotes (") enclosing all the text values in the cells.
>
> In order to do that, I added a 'noquotes` option to the :results  
> header
> argument.
>
> Here's my patch. As I'm not an elisp expert, please tell me if  
> there's a
> better/safer way to do that or maybe that it already exists an  
> option to do
> that...
>
> --8<---------------cut here---------------start------------->8---
> diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/ 
> org-babel.el
> index 4c9bff5..13c8237 100644
> --- a/contrib/babel/lisp/org-babel.el
> +++ b/contrib/babel/lisp/org-babel.el
> @@ -706,6 +706,9 @@ code ---- the results are extracted in the  
> syntax of the source
>           code of the language being evaluated and are added
>           inside of a #+BEGIN_SRC block with the source-code
>           language set appropriately."
> +  (setq outputformat "%S")
> +  (if (member "noquotes" result-params)
> +      (setq outputformat "%s"))
>   (if (stringp result)
>       (progn
>         (setq result (org-babel-clean-text-properties result))
> @@ -739,7 +742,7 @@ code ---- the results are extracted in the  
> syntax of the source
> 			     (if (and (listp (car result))
>                                       (listp (cdr (car result))))
> 				 result (list result))
> -			     '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
> +			     '(:fmt (lambda (cell) (format outputformat cell)))) "\n"))
> 	    (forward-line -1) (org-cycle))
> 	   ((member "file" result-params)
> 	    (insert result))
> @@ -827,7 +830,8 @@ parameters when merging lists."
>   (let ((results-exclusive-groups
> 	 '(("file" "vector" "table" "scalar" "raw" "org" "html" "latex"  
> "code" "pp")
> 	   ("replace" "silent")
> -	   ("output" "value")))
> +	   ("output" "value")
> +           ("noquotes")))
> 	(exports-exclusive-groups
> 	 '(("code" "results" "both" "none")))
> 	params results exports tangle cache vars var ref)
> --8<---------------cut here---------------end--------------->8---
>

This does work for me.  Grazie.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-18 18:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-17 20:15 [babel] Idiomatic handling of quotes Thomas S. Dye
     [not found] ` <D66D7851-44D9-490A-8EA5-271BFE96FEEB-P0awH739Ni4AvxtiuMwx3w@public.gmane.org>
2009-12-18  9:20   ` Francesco Pizzolante
2009-12-18 18:22     ` Thomas S. Dye

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.