From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Thomas S. Dye" Subject: [babel] Idiomatic handling of quotes Date: Thu, 17 Dec 2009 10:15:06 -1000 Message-ID: Mime-Version: 1.0 (Apple Message framework v936) Content-Type: multipart/mixed; boundary="===============1842464883==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLMl3-0007xY-OM for emacs-orgmode@gnu.org; Thu, 17 Dec 2009 15:15:33 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLMky-0007mf-Hl for emacs-orgmode@gnu.org; Thu, 17 Dec 2009 15:15:33 -0500 Received: from [199.232.76.173] (port=45996 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLMky-0007mP-Ap for emacs-orgmode@gnu.org; Thu, 17 Dec 2009 15:15:28 -0500 Received: from outbound-mail-113.bluehost.com ([69.89.24.3]:49565) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1NLMkv-000067-Ug for emacs-orgmode@gnu.org; Thu, 17 Dec 2009 15:15:28 -0500 Received: from [72.253.144.27] (helo=potofo-ou.westell.com) by box472.bluehost.com with esmtpa (Exim 4.69) (envelope-from ) id 1NLMke-000208-D2 for emacs-orgmode@gnu.org; Thu, 17 Dec 2009 13:15:09 -0700 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode --===============1842464883== Content-Type: multipart/alternative; boundary=Apple-Mail-2--694134654 --Apple-Mail-2--694134654 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit 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 --Apple-Mail-2--694134654 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Aloha = all,

In the example below, note that the = R representation of the directory listing es= capes the quotes in the original and en= closes it all in a second set of q= uotes, 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=3D"")

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 =3D = 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

=

= --Apple-Mail-2--694134654-- --===============1842464883== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --===============1842464883==-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Francesco Pizzolante Subject: Re: [babel] Idiomatic handling of quotes Date: Fri, 18 Dec 2009 10:20:53 +0100 Message-ID: <87iqc4hc3u.fsf@missioncriticalit.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: In-Reply-To: (Thomas S. Dye's message of "Thu, 17 Dec 2009 10:15:06 -1000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org 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 Subject: [Orgmode] [babel] double quotes in tables To: mailing-list-org-mode 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Thomas S. Dye" Subject: Re: [babel] Idiomatic handling of quotes Date: Fri, 18 Dec 2009 08:22:49 -1000 Message-ID: References: <87iqc4hc3u.fsf@missioncriticalit.com> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLhTg-0005vv-79 for emacs-orgmode@gnu.org; Fri, 18 Dec 2009 13:23:00 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLhTa-0005pz-UM for emacs-orgmode@gnu.org; Fri, 18 Dec 2009 13:22:59 -0500 Received: from [199.232.76.173] (port=41548 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLhTa-0005pe-PD for emacs-orgmode@gnu.org; Fri, 18 Dec 2009 13:22:54 -0500 Received: from outbound-mail-104.bluehost.com ([69.89.22.14]:37827) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1NLhTa-0007Ja-6k for emacs-orgmode@gnu.org; Fri, 18 Dec 2009 13:22:54 -0500 In-Reply-To: <87iqc4hc3u.fsf@missioncriticalit.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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 > Subject: [Orgmode] [babel] double quotes in tables > To: mailing-list-org-mode > 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