From mboxrd@z Thu Jan 1 00:00:00 1970 From: Emmanuel Charpentier Subject: Re: Possible bug (?): :noweb doesn't respect indentations (at least i R/BUGS/JAGS). Date: Tue, 09 Apr 2019 19:42:47 +0200 Message-ID: References: <92dddcaf59f004e86fee9b2b56ec51f4a686c656.camel@free.fr> <6E47C74E-93E0-4411-AA30-90DFECFAE786@ucsd.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([209.51.188.92]:49516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDuln-00072g-RG for emacs-orgmode@gnu.org; Tue, 09 Apr 2019 13:42:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDulm-0004NH-Pr for emacs-orgmode@gnu.org; Tue, 09 Apr 2019 13:42:51 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]:41502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDulm-0004M3-14 for emacs-orgmode@gnu.org; Tue, 09 Apr 2019 13:42:50 -0400 In-Reply-To: <6E47C74E-93E0-4411-AA30-90DFECFAE786@ucsd.edu> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: "Berry, Charles" Cc: emacs-orgmode Thanks ! Ths switch excaped my attention, probably because it is buried in a "literal example" section, which I didn't connect to noweb care and feeding... Maybe the "noweb" section might benefit of a discrete recall of relevant switches ? Thanks again ! -- Emmanuel Charpentier Le mardi 09 avril 2019 =C3=A0 16:19 +0000, Berry, Charles a =C3=A9crit : > > On Apr 8, 2019, at 4:01 PM, Emmanuel Charpentier < > > emm.charpentier@free.fr> wrote: > >=20 > > Compare this org source: > >=20 > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > # A small :noweb mystery: indentation > >=20 > > #+property: header-args:R :session > > #+options: toc:nil > > #+author: > > #+date: > >=20 > > The structure of a probablity proble can be represented by a ~JAGS~ > > code snippet: > > #+name: Struct > > #+begin_src R :eval never :exports code > > for (i in 1:nObs) { > > for (j in 1:nZ) { > > Z[i,j] ~ dbern(P[i,j]) > > logit(P[i,j]) <- alpha + beta[j]*X[i] > > } > > } > > #+end_src > >=20 > > The same code snippet can be used for simulation: > >=20 >=20 > See Org Manual (org) Literal Examples for information about the -i > switch >=20 > Try:=20 >=20 > #+begin_src R -i :exports code :results none :noweb yes >=20 > instead of this: >=20 > > #+begin_src R :exports code :results none :noweb yes > > library(rjags) > > library(coda) > > ## Reproducibility ? > > set.seed(813) > > Params <- local({ > > nObs <- 500 > > nZ <- 5 > > X <- rnorm(nObs) > > alpha <- rnorm(1,0,3) > > beta <- rnorm(nZ,-1,2) > > list( > > nObs=3DnObs, > > nZ=3DnZ, > > X=3DX, > > alpha=3Dalpha, > > beta=3Dbeta) > > }) > > ## Wrap model code > > M <- > > "model { > > <> > > }" > > ## Compilation > > JM <- jags.model(textConnection(M), data=3DParams, n.adapt=3D1, > > n.chains=3D1) > > ## Forward sampling > > JS <- coda.samples(JM, "Z", n.iter=3D1) > > #+end_src > >=20 > > and for inference, after adding priors of parameters: > >=20 > > #+name: Priors > > #+begin_src R :eval never :exports code > > ## Priors > > alpha ~ dt(0, 1e-2, 3) > > for (j in 1:nZ) { > > beta[j] ~ dt(0,1e-2, 3) > > } > > #+end_src > >=20 >=20 > And again here: >=20 >=20 > > #+name: Inference > > #+begin_src R :noweb yes :exports code > > Data <- list( > > nObs=3DParams$nObs, > > nZ=3DParams$nZ, > > X=3DParams$X, > > Z=3Dmatrix(as.matrix(JS), ncol=3DParams$nZ, byrow=3DFALSE)) > > ## Wrap inference model > > MI <- > > "model { > > <> > > <> > > }" > > ## Compilation > > JMI <- jags.model(textConnection(MI), Data, n.chains=3D4) > > ## Inference sampling > > JMS <- coda.samples(JMI, c("alpha", "beta"), n.iter=3D1000) > > #+end_src > >=20 > > #+RESULTS: Inference > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > >=20 > > With the result of its export to Ascii: > >=20 >=20 > [snip] >=20 >=20 > > The indentation is not respected in the included JAGS snippets. > > Further > > attempts with exporting to PDF (both the built-in exporter and ox- > > pandoc) and DOCX (ox-pandoc) show that the problem remains the > > same, > > but, IIRC, with slight variations in whitespace. > >=20 > > That's not serious (just ugly) for R/JAGS ; but it might be serious > > for > > Python/Sage, where whitespace is syntaxic. > >=20 > > Thoughts ? > >=20 >=20 > Try the switch. >=20 > HTH, >=20 > Chuck