From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Berry, Charles" Subject: Re: Possible bug (?): :noweb doesn't respect indentations (at least i R/BUGS/JAGS). Date: Tue, 9 Apr 2019 16:19:53 +0000 Message-ID: <6E47C74E-93E0-4411-AA30-90DFECFAE786@ucsd.edu> References: <92dddcaf59f004e86fee9b2b56ec51f4a686c656.camel@free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([209.51.188.92]:58416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDtU7-0002If-Nw for emacs-orgmode@gnu.org; Tue, 09 Apr 2019 12:20:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDtU5-00023I-RN for emacs-orgmode@gnu.org; Tue, 09 Apr 2019 12:20:31 -0400 Received: from iport-acv2-out.ucsd.edu ([132.239.0.174]:45133) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1hDtU4-0001pB-WC for emacs-orgmode@gnu.org; Tue, 09 Apr 2019 12:20:29 -0400 In-Reply-To: <92dddcaf59f004e86fee9b2b56ec51f4a686c656.camel@free.fr> Content-Language: en-US Content-ID: <42CDA94B01386A439691A89A1991BC3E@AD.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: Emmanuel Charpentier Cc: emacs-orgmode > On Apr 8, 2019, at 4:01 PM, Emmanuel Charpentier 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 See Org Manual (org) Literal Examples for information about the -i switch Try:=20 #+begin_src R -i :exports code :results none :noweb yes instead of this: > #+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 And again here: > #+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 [snip] > 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 Try the switch. HTH, Chuck=