* cannot execute org-mode code from the front page tutorial. @ 2014-08-15 16:37 jenia.ivlev 2014-08-15 17:04 ` Thomas S. Dye 0 siblings, 1 reply; 9+ messages in thread From: jenia.ivlev @ 2014-08-15 16:37 UTC (permalink / raw) To: emacs-orgmode Hello. I'm trying to go through the org-mode tutorial on its official page. However, I have trouble execute the code there" #+NAME: tbl-example-data() #+BEGIN_SRC R :results value runif(n=5, min=0, max=1) #+END_SRC #+RESULTS: tbl-example-data | 0.565871287835762 | | 0.457158328965306 | | 0.0498181856237352 | | 0.988381117349491 | | 0.898329895688221 | #+NAME: R-mean(x) #+BEGIN_SRC R :var x=tbl-example-data mean(x) #+END_SRC #+call: R-mean(x=tbl-example-data) It returns me: Reference 'R-mean' not found in this buffer. Can someone please tell me how can I fix this error? Thanks in advance for your time and kind help. Jenia. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-15 16:37 cannot execute org-mode code from the front page tutorial jenia.ivlev @ 2014-08-15 17:04 ` Thomas S. Dye 2014-08-15 18:40 ` Nick Dokos 0 siblings, 1 reply; 9+ messages in thread From: Thomas S. Dye @ 2014-08-15 17:04 UTC (permalink / raw) To: jenia.ivlev; +Cc: emacs-orgmode Aloha Jenia, jenia.ivlev@gmail.com (jenia.ivlev) writes: > Hello. > > I'm trying to go through the org-mode tutorial on its official page. > > However, I have trouble execute the code there" > > > #+NAME: tbl-example-data() > #+BEGIN_SRC R :results value > runif(n=5, min=0, max=1) > #+END_SRC > > #+RESULTS: tbl-example-data > | 0.565871287835762 | > | 0.457158328965306 | > | 0.0498181856237352 | > | 0.988381117349491 | > | 0.898329895688221 | > > > > #+NAME: R-mean(x) > #+BEGIN_SRC R :var x=tbl-example-data > mean(x) > #+END_SRC > > > > > #+call: R-mean(x=tbl-example-data) > > > It returns me: > > > > Reference 'R-mean' not found in this buffer. > FWIW, this code doesn't work for me, either, using a recent Org-mode from git. For others able to help, the "org-mode tutorial on its official page" that Jenia refers to is http://orgmode.org/worg/org-contrib/babel/intro.html#spreadsheet hth, Tom -- Thomas S. Dye http://www.tsdye.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-15 17:04 ` Thomas S. Dye @ 2014-08-15 18:40 ` Nick Dokos 2014-08-15 23:36 ` jenia.ivlev 2014-08-16 16:49 ` Charles Berry 0 siblings, 2 replies; 9+ messages in thread From: Nick Dokos @ 2014-08-15 18:40 UTC (permalink / raw) To: emacs-orgmode tsd@tsdye.com (Thomas S. Dye) writes: > Aloha Jenia, > > jenia.ivlev@gmail.com (jenia.ivlev) writes: > >> Hello. >> >> I'm trying to go through the org-mode tutorial on its official page. >> >> However, I have trouble execute the code there" >> >> >> #+NAME: tbl-example-data() >> #+BEGIN_SRC R :results value >> runif(n=5, min=0, max=1) >> #+END_SRC >> >> #+RESULTS: tbl-example-data >> | 0.565871287835762 | >> | 0.457158328965306 | >> | 0.0498181856237352 | >> | 0.988381117349491 | >> | 0.898329895688221 | >> >> >> >> #+NAME: R-mean(x) >> #+BEGIN_SRC R :var x=tbl-example-data >> mean(x) >> #+END_SRC >> >> >> >> >> #+call: R-mean(x=tbl-example-data) >> >> >> It returns me: >> >> >> >> Reference 'R-mean' not found in this buffer. >> > > FWIW, this code doesn't work for me, either, using a recent Org-mode from > git. > > > For others able to help, the "org-mode tutorial on its official page" > that Jenia refers to is > http://orgmode.org/worg/org-contrib/babel/intro.html#spreadsheet > I simplified the org file that leads to the error: --8<---------------cut here---------------start------------->8--- #+name: tbl-example-data | foo | |-------------------| | 0.996612656628713 | | 0.148018079344183 | | 0.560482589527965 | | 0.329234286677092 | | 0.99839389254339 | #+BEGIN_SRC R :var x=tbl-example-data mean(x) #+END_SRC #+RESULTS: : nil --8<---------------cut here---------------end--------------->8--- Running it in the debugger, I think what it does is the equivalent of --8<---------------cut here---------------start------------->8--- x <- local({con <- textConnection("0.996612656628713 0.148018079344183 0.560482589527965 0.329234286677092 0.99839389254339") res <- read.table( con, header = FALSE, row.names = NULL, sep = "\t", as.is = TRUE ) close(con) res}) mean(x) --8<---------------cut here---------------end--------------->8--- and trying this on the command line, I get an error: ,---- | > x <- local({con <- textConnection("0.996612656628713 | 0.148018079344183 | 0.560482589527965 | 0.329234286677092 | 0.99839389254339") | res <- read.table( | con, | header = FALSE, | row.names = NULL, | sep = "\t", | as.is = TRUE | ) | close(con) | res}) | | + + + + + + + + + + + + + > > x | V1 | 1 0.9966127 | 2 0.1480181 | 3 0.5604826 | 4 0.3292343 | 5 0.9983939 | > mean(x) | [1] NA | Warning message: | In mean.default(x) : argument is not numeric or logical: returning NA `---- [Disclaimer: from this point on, I'm mostly talking about R - I know nothing about R] Fumbling around with typeof(x) and help(list), I stumbled upon unlist() and used it in the evaluation of x: ,---- | > x <- local({con <- textConnection("0.996612656628713 | 0.148018079344183 | 0.560482589527965 | 0.329234286677092 | 0.99839389254339") | res <- read.table( | con, | header = FALSE, | row.names = NULL, | sep = "\t", | as.is = TRUE | ) | close(con) | unlist(res)}) | + + + + + + + + + + + + + > x | V11 V12 V13 V14 V15 | 0.9966127 0.1480181 0.5604826 0.3292343 0.9983939 | > mean(x) | [1] 0.6065483 | > `---- Seems to work. Based on this purely empirical observation, I applied this patch to org: --8<---------------cut here---------------start------------->8--- diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 9f4eb4b..f3338cb 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -106,7 +106,7 @@ this variable.") as.is = TRUE ) close(con) - res + unlist(res) })" "R code used to transfer a table defined as a variable from org to R. This function is used when the table contains a header.") @@ -126,7 +126,7 @@ This function is used when the table contains a header.") col.names = paste(\"V\", seq_len(%d), sep =\"\") ) close(con) - res + unlist(res) })" "R code used to transfer a table defined as a variable from org to R. This function is used when the table does not contain a header.") --8<---------------cut here---------------end--------------->8--- and the org file at the top works. But this clearly needs to be vetted by an R expert. The original example needs some changes to work, mainly simplification of the #+names: --8<---------------cut here---------------start------------->8--- #+NAME: tbl-example-data #+BEGIN_SRC R :results value runif(n=5, min=0, max=1) #+END_SRC #+NAME: R-mean #+BEGIN_SRC R :var x=tbl-example-data mean(x) #+END_SRC #+call: R-mean(x=tbl-example-data) --8<---------------cut here---------------end--------------->8--- And assuming this is correct, the worg page will need to be corrected too. -- Nick ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-15 18:40 ` Nick Dokos @ 2014-08-15 23:36 ` jenia.ivlev 2014-08-16 2:41 ` Nick Dokos 2014-08-16 2:43 ` Nick Dokos 2014-08-16 16:49 ` Charles Berry 1 sibling, 2 replies; 9+ messages in thread From: jenia.ivlev @ 2014-08-15 23:36 UTC (permalink / raw) To: emacs-orgmode I can't make the changes - apply the your path - because my ob-R.el file is completly different, its a elisp file and doesnt contain any R code. The file is located at /usr/share/emacs/24.3/lisp/org/ob-R.el Can you tell me how do I proceed to apply our changes to my emacs? Thanks again for your help. Jenia. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-15 23:36 ` jenia.ivlev @ 2014-08-16 2:41 ` Nick Dokos 2014-08-16 2:43 ` Nick Dokos 1 sibling, 0 replies; 9+ messages in thread From: Nick Dokos @ 2014-08-16 2:41 UTC (permalink / raw) To: emacs-orgmode; +Cc: Rainer M. Krug jenia.ivlev@gmail.com (jenia.ivlev) writes: > I can't make the changes - apply the your path - because my ob-R.el file > is completly different, its a elisp file and doesnt contain any R code. > > The file is located at /usr/share/emacs/24.3/lisp/org/ob-R.el > > Can you tell me how do I proceed to apply our changes to my emacs? > > Thanks again for your help. > Sorry, I tested latest org (and wrongly assumed that that's what you are using). Can you post the results of M-x org-version here? I'll try to take a look at what goes wrong in that version. For the record, the patch modifies the initialization of two lisp constants that ob-R.el defines in its latest incarnation. This change was introduced by Rainer Krug on June 23 with commit 4c415f38a5c71b45409faf9b59030ee7cee6abad. Before that, the values were transmitted through temporary files. I hope Rainer (cc'ed) takes a look at this thread: he is clearly the R expert here. -- Nick ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-15 23:36 ` jenia.ivlev 2014-08-16 2:41 ` Nick Dokos @ 2014-08-16 2:43 ` Nick Dokos 1 sibling, 0 replies; 9+ messages in thread From: Nick Dokos @ 2014-08-16 2:43 UTC (permalink / raw) To: emacs-orgmode jenia.ivlev@gmail.com (jenia.ivlev) writes: > I can't make the changes - apply the your path - because my ob-R.el file > is completly different, its a elisp file and doesnt contain any R code. > > The file is located at /usr/share/emacs/24.3/lisp/org/ob-R.el > > Can you tell me how do I proceed to apply our changes to my emacs? > > Thanks again for your help. > > Jenia. > > > Sorry, I tested latest org (and wrongly assumed that that's what you are using). Can you post the results of M-x org-version here? I'll try to take a look at what goes wrong in that version. For the record, the patch modifies the initialization of two lisp constants that ob-R.el defines in its latest incarnation. This change was introduced by Rainer Krug on June 23 with commit 4c415f38a5c71b45409faf9b59030ee7cee6abad. Before that, the values were transmitted through temporary files. I hope Rainer takes a look at this thread: he is clearly the R expert here. -- Nick -- Nick ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-15 18:40 ` Nick Dokos 2014-08-15 23:36 ` jenia.ivlev @ 2014-08-16 16:49 ` Charles Berry 2014-08-16 17:13 ` Thomas S. Dye 2014-08-16 21:01 ` Nick Dokos 1 sibling, 2 replies; 9+ messages in thread From: Charles Berry @ 2014-08-16 16:49 UTC (permalink / raw) To: emacs-orgmode Nick Dokos <ndokos <at> gmail.com> writes: > > tsd <at> tsdye.com (Thomas S. Dye) writes: > > > Aloha Jenia, > > > > jenia.ivlev <at> gmail.com (jenia.ivlev) writes: > > > >> Hello. > >> > >> I'm trying to go through the org-mode tutorial on its official page. > >> [discussion showing that (if (listp value)...) generates a data.frame deleted] [delete patch turning a data.frame into a vector] > And assuming this is correct, the worg page will need to be corrected > too. > No patch is needed. The point of the code in org-babel-R-assign-elisp is to create a data.frame when `value' is a list. The patch adding `unlist(res)' turns it into an ordinary vector. This will break almost all uses of :var in R scr blocks. I don't think this example could have worked for a long while - turning elisp lists into R data.frames has been a feature for a good while. Also, note the use of `sbe' vs `org-sbe' in the formula. #+TBLFM: @2$1='(sbe "R-mean" (x "tbl-example-data()")) Use `colMeans(x)' to fix the worg page. HTH, Chuck ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-16 16:49 ` Charles Berry @ 2014-08-16 17:13 ` Thomas S. Dye 2014-08-16 21:01 ` Nick Dokos 1 sibling, 0 replies; 9+ messages in thread From: Thomas S. Dye @ 2014-08-16 17:13 UTC (permalink / raw) To: Charles Berry; +Cc: emacs-orgmode Charles Berry <ccberry@ucsd.edu> writes: > Nick Dokos <ndokos <at> gmail.com> writes: > >> >> tsd <at> tsdye.com (Thomas S. Dye) writes: >> >> > Aloha Jenia, >> > >> > jenia.ivlev <at> gmail.com (jenia.ivlev) writes: >> > >> >> Hello. >> >> >> >> I'm trying to go through the org-mode tutorial on its official page. >> >> > > [discussion showing that (if (listp value)...) generates a data.frame > deleted] > > [delete patch turning a data.frame into a vector] > >> And assuming this is correct, the worg page will need to be corrected >> too. >> > > No patch is needed. > > The point of the code in org-babel-R-assign-elisp is to create a data.frame > when `value' is a list. > > The patch adding `unlist(res)' turns it into an ordinary vector. > > This will break almost all uses of :var in R scr blocks. > > I don't think this example could have worked for a long while - turning > elisp lists into R data.frames has been a feature for a good while. > Also, note the use of `sbe' vs `org-sbe' in the formula. > > #+TBLFM: @2$1='(sbe "R-mean" (x "tbl-example-data()")) > > > Use `colMeans(x)' to fix the worg page. Also, it appears that babel no longer supports passing variables through the #+name: line. I don't use this syntax and can't remember now whether support for it was removed, or if it just withered away. At any rate, if I use the #+header: syntax then I can get the example working partially. It is possible then to get the OP's desired result with the #+call: line. Changing (sbe ...) to (org-sbe ...) in the table calculates the mean, but doesn't yield a real table. The initial "|" on the last line is missing. #+NAME: tbl-example-data #+BEGIN_SRC R :results value runif(n=5, min=0, max=1) #+END_SRC #+RESULTS: tbl-example-data | 0.850588989211246 | | 0.138243367196992 | | 0.382761054905131 | | 0.00688096368685365 | | 0.394350948277861 | #+NAME: R-mean #+header: :var x="" #+header: :results output #+BEGIN_SRC R colMeans(x) #+END_SRC #+call: R-mean(x=tbl-example-data) #+results: : V1 : 0.4273072 #+tblname: summaries | mean | |------| | V1 | 0.2574993| #+TBLFM: @2$1='(org-sbe "R-mean" (x "tbl-example-data()")) hth, Tom -- Thomas S. Dye http://www.tsdye.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cannot execute org-mode code from the front page tutorial. 2014-08-16 16:49 ` Charles Berry 2014-08-16 17:13 ` Thomas S. Dye @ 2014-08-16 21:01 ` Nick Dokos 1 sibling, 0 replies; 9+ messages in thread From: Nick Dokos @ 2014-08-16 21:01 UTC (permalink / raw) To: emacs-orgmode Charles Berry <ccberry@ucsd.edu> writes: > Nick Dokos <ndokos <at> gmail.com> writes: > >> >> tsd <at> tsdye.com (Thomas S. Dye) writes: >> >> > Aloha Jenia, >> > >> > jenia.ivlev <at> gmail.com (jenia.ivlev) writes: >> > >> >> Hello. >> >> >> >> I'm trying to go through the org-mode tutorial on its official page. >> >> > > [discussion showing that (if (listp value)...) generates a data.frame > deleted] > Ah, that's what's happening! > [delete patch turning a data.frame into a vector] > >> And assuming this is correct, the worg page will need to be corrected >> too. >> > > No patch is needed. > > The point of the code in org-babel-R-assign-elisp is to create a data.frame > when `value' is a list. > > The patch adding `unlist(res)' turns it into an ordinary vector. > > This will break almost all uses of :var in R scr blocks. > > I don't think this example could have worked for a long while - turning > elisp lists into R data.frames has been a feature for a good while. > Also, note the use of `sbe' vs `org-sbe' in the formula. > > #+TBLFM: @2$1='(sbe "R-mean" (x "tbl-example-data()")) > > Use `colMeans(x)' to fix the worg page. > Thanks! As penance, I'll try to fix the worg page (unless somebody beats me to it of cource). -- Nick ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-08-16 21:02 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-08-15 16:37 cannot execute org-mode code from the front page tutorial jenia.ivlev 2014-08-15 17:04 ` Thomas S. Dye 2014-08-15 18:40 ` Nick Dokos 2014-08-15 23:36 ` jenia.ivlev 2014-08-16 2:41 ` Nick Dokos 2014-08-16 2:43 ` Nick Dokos 2014-08-16 16:49 ` Charles Berry 2014-08-16 17:13 ` Thomas S. Dye 2014-08-16 21:01 ` Nick Dokos
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git 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).