GithubHelp home page GithubHelp logo

Comments (5)

tntdynamight avatar tntdynamight commented on September 4, 2024

I found a better solution: With :results output drawer, the extra file isn't necessary, for example in R you can do:

#+BEGIN_SRC R :results output drawer :exports none
# Not APA style, which asks for: between cond1 (M=xx, SD=xx) and cond2 (M=xx, SD=xx); t(df)=xx,p=xx
# One could report (M=xx, CI=xx), or put Means and SD
report_ttest <- function(label,ttest,k=2) {
    decify <- function(x, k) format(round(x, k), nsmall=k)
    prefix <- paste("#+MACRO:",label," ")
    tdf    <- paste("t(",decify(ttest$parameter,2),")=",decify(ttest$statistic,k),sep="")
    p      <- paste(", p=",decify(ttest$p.value,k),sep = "")
    outstr <- paste(prefix,tdf,p,sep="")
    return(outstr)
}
AvsO <- t.test(c(1,3,5),c(6,6,6))
AvsO2 <- t.test(c(1,2,1),c(6,7,6))
AvsOrep <- report_ttest("AvsO",AvsO)
AvsOrep2 <- report_ttest("AvsO2",AvsO2)

print(cat(c(AvsOrep,AvsOrep2),sep="\n"))
#+END_SRC

and You will get:

#+RESULTS:
:RESULTS:
#+MACRO: AvsO  t(2.00)=-2.60, p=0.12
#+MACRO: AvsO2  t(4.00)=-10.61, p=0.00
NULL
:END:

So you can Use (anywhere in Your file):

Apples were no different from oranges in test1 ({{{AvsO}}}), but they were in test 2 ({{{AvsO2}}})

which exports to:

Apples were no different from oranges in test1 (t(2.00)=-2.60, p=0.12), but they were in test 2 (t(4.00)=-10.61, p=0.00)

from orgpaper.

vikasrawal avatar vikasrawal commented on September 4, 2024

The org babel docs has this for inline code.

https://org-babel.readthedocs.io/en/latest/eval/#inline-babel-calls

This can be used for in-text variables. What the pros and cons of using this or the macros.

Vikas

from orgpaper.

tntdynamight avatar tntdynamight commented on September 4, 2024

The advantage of the macros is that the information flows from potentially larger code blocks towards orgmode. I typically have longer code blocks that I don't want to run all at once or again on export, but I want variables or results to be available in-text and updateable by rerunning the code-block if necessary - but not obligatorily upon export. My examples above are somewhat trivial for brevity, but for longer calculations I haven't found a better way yet to make certain variables from longer code blocks accessible for in-text reference.

from orgpaper.

vikasrawal avatar vikasrawal commented on September 4, 2024

I agree, running all the code blocks upon export can soon become problematic. I have never used in-text variables myself, and therefore, speak without experience. Your approach indeed has the advantage that export would be a snap. But my concern is that the document would be cluttered with too many MACROs.

If you use a persistent R session with the document, there is another possible approach. You can create a dataframe with two variables, key and value, in which you store values of each variable that is going to be used in the text. These values could be inserted/replaced by various code blocks. Then, the inline code only needs to read a particular value from a data frame. That should be reasonably quick.

Do you think that can be a reasonable way of doing things?

from orgpaper.

tntdynamight avatar tntdynamight commented on September 4, 2024

That should work. I guess it kind of depends where you prefer to have your clutter. My considerations:

  1. I haven't actually gotten that to run (you need to run :session and call that session inline). - if you have a working example that would be great.
    1.1. maybe number to string conversion is necessary? -> in that case I prefer to worry about it in the language code block, not in my text.
  2. it's still less readable and pretty than macro - compare:
    Number of Subjects was src_R[:session parso ]{as.character(parstab$nsubs)}.
    with
    Number of Subjects was {{{parstab_nsubs}}}
  3. Clutter is added by manually defining which variables you want to make available through Macros in the code-block. in the .org file it's not bad at all however, as you store the macro definitions in a drawer anyways.

P.S. The very best way I could imagine would be to allow remote references to table fields from in-text (so far only possible from other tables), ideally being able to call fields by column and/or row names of that table. That way I would include the whole table as supplementary material and easily reference parameters, results, anything from a table, something like:

from orgpaper.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.