From: Vikas Rawal <vikaslists@agrarianresearch.org>
To: "Charles C. Berry" <ccberry@ucsd.edu>
Cc: William Denton <wtd@pobox.com>,
org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Trouble evaluating R source code blocks with C-c C-c
Date: Sun, 29 May 2016 18:43:58 +0530 [thread overview]
Message-ID: <5F862231-C04A-4BF6-8A2A-2377AF000374@agrarianresearch.org> (raw)
In-Reply-To: <alpine.OSX.2.20.1605280958230.638@charles-berrys-macbook.local>
[-- Attachment #1: Type: text/plain, Size: 12763 bytes --]
And this time it has this additional line: run-hook-with-args-until-success(org-babel-execute-safely-maybe)
------------------
sit-for(0.25)
org-babel-comint-eval-invisibly-and-wait-for-file("type2" "/var/folders/hj/hqfjch716qg5php160jbtfgh0000gn/T/babel-53134TSq/R-53134vJF" "{\n function(object,transfer.file) {\n object\n invisible(\n if (\n inherits(\n try(\n {\n tfile<-tempfile()\n write.table(object, file=tfile, sep=\"\\t\",\n na=\"nil\",row.names=FALSE,col.names=TRUE,\n quote=FALSE)\n file.rename(tfile,transfer.file)\n },\n silent=TRUE),\n \"try-error\"))\n {\n if(!file.exists(transfer.file))\n file.create(transfer.file)\n }\n )\n }\n}(object=.Last.value,transfer.file=\"/var/folders/hj/hqfjch716qg5php160jbtfgh0000gn/T/babel-53134TSq/R-53134vJF\")")
org-babel-R-evaluate-session("type2" "library(plyr)\nlibrary(Hmisc)\ng->tempg\n\n # CV_untreated\nas.integer(tempg$state_region/10)->tempg$State.code.68\nfactor(tempg$State.code.68)->tempg$State.code.68\ndata.frame(State=0,adjusted_cv=0)->e\n\nfor (i in c(1:35)) {\n subset(tempg,as.numeric(tempg$State.code.68)==i)->dd\n wtd.var(dd$adj_cal,weight=dd$weight)^0.5/wtd.mean(dd$adj_cal,weight=dd$weight)->cvs\n data.frame(State=i,adjusted_cv=cvs)->e1\n rbind(e,e1)->e\n}\n\nddply(tempg,.(State.code.68),summarise,value=wtd.mean(adj_cal,weight))->s1\n\ndata.frame(State=99,adjusted_cv=0)->f2\nwtd.var(tempg$adj_cal,weight=tempg$weight)^0.5/wtd.mean(tempg$adj_cal,weight=tempg$weight)->f2[1,2]\nrbind(e,f2)->cv1\n\n # CV_grouped data\nddply(tempg,.(sex,agegroup,fractile_adj),summarise,calories=wtd.mean(adj_cal,weight))->l1\nddply(tempg,.(sex,agegroup,fractile_adj),summarise,weight=sum(weight))->w\n\nmerge(w,l1,by=c(\"sex\",\"agegroup\",\"fractile_adj\"))->l1\n\nddply(tempg,.(fractile_adj_state,State.code.68,agegroup,sex),summarise,value=wtd.mean(adj_cal,weight))->s3\n\nddply(tempg,.(fractile_adj_state,State.code.68,agegroup,sex),summarise,sum_weight=sum(weight))->sw\n\nmerge(s3,sw,by=c(\"fractile_adj_state\",\"State.code.68\",\"agegroup\",\"sex\"))->s3\n\nfactor(s3$State.code.68)->s3$State.code.68\n\ndata.frame(State=99,grouped_cv=wtd.var(l1$calories,weight=l1$weight)^0.5/wtd.mean(l1$calories,weight=l1$weight))->cv3\n\nfor (i in c(1:35)) {\n subset(s3,as.numeric(s3$State.code.68)==i)->s3sub\n data.frame(State=i,grouped_cv=wtd.var(s3sub$value,s3sub$sum_weight)^0.5/wtd.mean(s3sub$value,s3sub$sum_weight))->t1\n rbind(cv3,t1)->cv3\n}\n\n# CV_from regression model\nregdata->p\nexp(predict.lm(reg))->p$predicted_cal\n\ndata.frame(State=99,predicted_cv=wtd.var(p$predicted_cal,weight=p$weight)^0.5/wtd.mean(p$predicted_cal,weight=p$weight),adjr2=summary(reg)$adj.r.squared)->cv2\n\n\n#data.frame(State=0,predicted_cv=0,adjr2=0)->e\n\nfor (i in c(1:35)) {\n subset(regdata,as.numeric(p$State.code.68)==i)->dd\n factor(dd$state_region)->dd$state_region\nfmla <- as.formula(\n ifelse(length(levels(dd$state_region))==1,\"log_cal~sector+sex+AgeChild+AgeAdult+foodprice+log(MPCE)\",\"log_cal~sector+sex+AgeChild+AgeAdult+foodprice+log(MPCE)+state_region\"))\n\n\n lm(fmla,data=dd,weights=weight)->regstate\n exp(predict.lm(regstate))->dd$predicted_cal\n wtd.var(dd$predicted_cal,weight=dd$weight)^0.5/wtd.mean(dd$predicted_cal,weight=dd$weight)->cvs\n data.frame(State=i,predicted_cv=cvs,adjr2=summary(regstate)$adj.r.squared)->e1\n rbind(cv2,e1)->cv2\n}\n\nsubset(cv2,select=-adjr2)->cv2\n\nmerge(cv1,cv3,by=\"State\")->t\nmerge(t,cv2,by=\"State\")->t\nmerge(t,statecode,by.x=\"State\",by.y=\"State.code.68\",all.x=TRUE)->t\nt$State.68[t$State==99]<-\"India\"\nround(t$grouped_cv,4)->t$grouped_cv\nround(t$adjusted_cv,4)->t$adjusted_cv\nround(t$predicted_cv,4)->t$predicted_cv\nnames(t)<-c(\"State.code.68\",\"CV (unit-level data)\",\"CV (grouped data)\",\"CV (based on regression model)\",\"State\")\nt->finvar\nt[order(t$State),c(5,2,3,4)]" value ("replace" "value") t nil)
org-babel-R-evaluate("type2" "library(plyr)\nlibrary(Hmisc)\ng->tempg\n\n # CV_untreated\nas.integer(tempg$state_region/10)->tempg$State.code.68\nfactor(tempg$State.code.68)->tempg$State.code.68\ndata.frame(State=0,adjusted_cv=0)->e\n\nfor (i in c(1:35)) {\n subset(tempg,as.numeric(tempg$State.code.68)==i)->dd\n wtd.var(dd$adj_cal,weight=dd$weight)^0.5/wtd.mean(dd$adj_cal,weight=dd$weight)->cvs\n data.frame(State=i,adjusted_cv=cvs)->e1\n rbind(e,e1)->e\n}\n\nddply(tempg,.(State.code.68),summarise,value=wtd.mean(adj_cal,weight))->s1\n\ndata.frame(State=99,adjusted_cv=0)->f2\nwtd.var(tempg$adj_cal,weight=tempg$weight)^0.5/wtd.mean(tempg$adj_cal,weight=tempg$weight)->f2[1,2]\nrbind(e,f2)->cv1\n\n # CV_grouped data\nddply(tempg,.(sex,agegroup,fractile_adj),summarise,calories=wtd.mean(adj_cal,weight))->l1\nddply(tempg,.(sex,agegroup,fractile_adj),summarise,weight=sum(weight))->w\n\nmerge(w,l1,by=c(\"sex\",\"agegroup\",\"fractile_adj\"))->l1\n\nddply(tempg,.(fractile_adj_state,State.code.68,agegroup,sex),summarise,value=wtd.mean(adj_cal,weight))->s3\n\nddply(tempg,.(fractile_adj_state,State.code.68,agegroup,sex),summarise,sum_weight=sum(weight))->sw\n\nmerge(s3,sw,by=c(\"fractile_adj_state\",\"State.code.68\",\"agegroup\",\"sex\"))->s3\n\nfactor(s3$State.code.68)->s3$State.code.68\n\ndata.frame(State=99,grouped_cv=wtd.var(l1$calories,weight=l1$weight)^0.5/wtd.mean(l1$calories,weight=l1$weight))->cv3\n\nfor (i in c(1:35)) {\n subset(s3,as.numeric(s3$State.code.68)==i)->s3sub\n data.frame(State=i,grouped_cv=wtd.var(s3sub$value,s3sub$sum_weight)^0.5/wtd.mean(s3sub$value,s3sub$sum_weight))->t1\n rbind(cv3,t1)->cv3\n}\n\n# CV_from regression model\nregdata->p\nexp(predict.lm(reg))->p$predicted_cal\n\ndata.frame(State=99,predicted_cv=wtd.var(p$predicted_cal,weight=p$weight)^0.5/wtd.mean(p$predicted_cal,weight=p$weight),adjr2=summary(reg)$adj.r.squared)->cv2\n\n\n#data.frame(State=0,predicted_cv=0,adjr2=0)->e\n\nfor (i in c(1:35)) {\n subset(regdata,as.numeric(p$State.code.68)==i)->dd\n factor(dd$state_region)->dd$state_region\nfmla <- as.formula(\n ifelse(length(levels(dd$state_region))==1,\"log_cal~sector+sex+AgeChild+AgeAdult+foodprice+log(MPCE)\",\"log_cal~sector+sex+AgeChild+AgeAdult+foodprice+log(MPCE)+state_region\"))\n\n\n lm(fmla,data=dd,weights=weight)->regstate\n exp(predict.lm(regstate))->dd$predicted_cal\n wtd.var(dd$predicted_cal,weight=dd$weight)^0.5/wtd.mean(dd$predicted_cal,weight=dd$weight)->cvs\n data.frame(State=i,predicted_cv=cvs,adjr2=summary(regstate)$adj.r.squared)->e1\n rbind(cv2,e1)->cv2\n}\n\nsubset(cv2,select=-adjr2)->cv2\n\nmerge(cv1,cv3,by=\"State\")->t\nmerge(t,cv2,by=\"State\")->t\nmerge(t,statecode,by.x=\"State\",by.y=\"State.code.68\",all.x=TRUE)->t\nt$State.68[t$State==99]<-\"India\"\nround(t$grouped_cv,4)->t$grouped_cv\nround(t$adjusted_cv,4)->t$adjusted_cv\nround(t$predicted_cv,4)->t$predicted_cv\nnames(t)<-c(\"State.code.68\",\"CV (unit-level data)\",\"CV (grouped data)\",\"CV (based on regression model)\",\"State\")\nt->finvar\nt[order(t$State),c(5,2,3,4)]" value ("replace" "value") t nil)
org-babel-execute:R("library(plyr)\nlibrary(Hmisc)\ng->tempg\n\n # CV_untreated\nas.integer(tempg$state_region/10)->tempg$State.code.68\nfactor(tempg$State.code.68)->tempg$State.code.68\ndata.frame(State=0,adjusted_cv=0)->e\n\nfor (i in c(1:35)) {\n subset(tempg,as.numeric(tempg$State.code.68)==i)->dd\n wtd.var(dd$adj_cal,weight=dd$weight)^0.5/wtd.mean(dd$adj_cal,weight=dd$weight)->cvs\n data.frame(State=i,adjusted_cv=cvs)->e1\n rbind(e,e1)->e\n}\n\nddply(tempg,.(State.code.68),summarise,value=wtd.mean(adj_cal,weight))->s1\n\ndata.frame(State=99,adjusted_cv=0)->f2\nwtd.var(tempg$adj_cal,weight=tempg$weight)^0.5/wtd.mean(tempg$adj_cal,weight=tempg$weight)->f2[1,2]\nrbind(e,f2)->cv1\n\n # CV_grouped data\nddply(tempg,.(sex,agegroup,fractile_adj),summarise,calories=wtd.mean(adj_cal,weight))->l1\nddply(tempg,.(sex,agegroup,fractile_adj),summarise,weight=sum(weight))->w\n\nmerge(w,l1,by=c(\"sex\",\"agegroup\",\"fractile_adj\"))->l1\n\nddply(tempg,.(fractile_adj_state,State.code.68,agegroup,sex),summarise,value=wtd.mean(adj_cal,weight))->s3\n\nddply(tempg,.(fractile_adj_state,State.code.68,agegroup,sex),summarise,sum_weight=sum(weight))->sw\n\nmerge(s3,sw,by=c(\"fractile_adj_state\",\"State.code.68\",\"agegroup\",\"sex\"))->s3\n\nfactor(s3$State.code.68)->s3$State.code.68\n\ndata.frame(State=99,grouped_cv=wtd.var(l1$calories,weight=l1$weight)^0.5/wtd.mean(l1$calories,weight=l1$weight))->cv3\n\nfor (i in c(1:35)) {\n subset(s3,as.numeric(s3$State.code.68)==i)->s3sub\n data.frame(State=i,grouped_cv=wtd.var(s3sub$value,s3sub$sum_weight)^0.5/wtd.mean(s3sub$value,s3sub$sum_weight))->t1\n rbind(cv3,t1)->cv3\n}\n\n# CV_from regression model\nregdata->p\nexp(predict.lm(reg))->p$predicted_cal\n\ndata.frame(State=99,predicted_cv=wtd.var(p$predicted_cal,weight=p$weight)^0.5/wtd.mean(p$predicted_cal,weight=p$weight),adjr2=summary(reg)$adj.r.squared)->cv2\n\n\n#data.frame(State=0,predicted_cv=0,adjr2=0)->e\n\nfor (i in c(1:35)) {\n subset(regdata,as.numeric(p$State.code.68)==i)->dd\n factor(dd$state_region)->dd$state_region\nfmla <- as.formula(\n ifelse(length(levels(dd$state_region))==1,\"log_cal~sector+sex+AgeChild+AgeAdult+foodprice+log(MPCE)\",\"log_cal~sector+sex+AgeChild+AgeAdult+foodprice+log(MPCE)+state_region\"))\n\n\n lm(fmla,data=dd,weights=weight)->regstate\n exp(predict.lm(regstate))->dd$predicted_cal\n wtd.var(dd$predicted_cal,weight=dd$weight)^0.5/wtd.mean(dd$predicted_cal,weight=dd$weight)->cvs\n data.frame(State=i,predicted_cv=cvs,adjr2=summary(regstate)$adj.r.squared)->e1\n rbind(cv2,e1)->cv2\n}\n\nsubset(cv2,select=-adjr2)->cv2\n\nmerge(cv1,cv3,by=\"State\")->t\nmerge(t,cv2,by=\"State\")->t\nmerge(t,statecode,by.x=\"State\",by.y=\"State.code.68\",all.x=TRUE)->t\nt$State.68[t$State==99]<-\"India\"\nround(t$grouped_cv,4)->t$grouped_cv\nround(t$adjusted_cv,4)->t$adjusted_cv\nround(t$predicted_cv,4)->t$predicted_cv\nnames(t)<-c(\"State.code.68\",\"CV (unit-level data)\",\"CV (grouped data)\",\"CV (based on regression model)\",\"State\")\nt->finvar\nt[order(t$State),c(5,2,3,4)]" ((:colname-names) (:rowname-names) (:result-params "replace" "value") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangle . "no") (:exports . "results") (:results . "replace value") (:hlines . "no") (:session . "type2") (:colnames . "yes") (:hline . "yes")))
org-babel-execute-src-block(nil)
org-babel-execute-src-block-maybe()
org-babel-execute-maybe()
org-babel-execute-safely-maybe()
run-hook-with-args-until-success(org-babel-execute-safely-maybe)
org-ctrl-c-ctrl-c(nil)
call-interactively(org-ctrl-c-ctrl-c nil nil)
command-execute(org-ctrl-c-ctrl-c)
> On 28-May-2016, at 10:31 pm, Charles C. Berry <ccberry@ucsd.edu> wrote:
>
>
> p.s. one more thing - below
>
> On Sat, 28 May 2016, Charles C. Berry wrote:
>
>> On Sat, 28 May 2016, William Denton wrote:
>>
>>> On 28 May 2016, Vikas Rawal wrote:
>>>> Thanks John. Appreciate that you cared to respond to such a vague query. I am at a loss with this one. It does not happen all the time. I think it happens when I am processing large datasets, and CPUs and RAM of my system are struggling to keep up. But I could be wrong.
>>> I've had the same kind of thing happen---but C-g (sometimes many) to kill the command, then rerunning, usually works without any trouble. Some strange combination of CPU and RAM and all that, the kind of thing that's not easily reproducible.
>>
>> Try this: customize `debug-on-quit' to `t' (and set for current session).
>>
>> Then when you have to quit via C-g, you will get a backtrace showing where the process was hanging and how it got there. This might be helpful in figuring out what is going on.
>>
>> Run your code and when you finally have to C-g out copy the *Backtrace* buffer and report it back here (or on the ESS list if appropriate).
>>
>
> After you copy the buffer, you should type 'q' in the *Backtrace* buffer to finish up or you may have some odd messages and hangups afterwards.
>
> Chuck
[-- Attachment #2: Type: text/html, Size: 20831 bytes --]
next prev parent reply other threads:[~2016-05-29 13:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-26 14:33 Trouble evaluating R source code blocks with C-c C-c Vikas Rawal
2016-05-26 18:52 ` John Hendy
2016-05-28 7:58 ` Vikas Rawal
2016-05-28 14:27 ` William Denton
2016-05-28 16:57 ` Charles C. Berry
2016-05-28 17:01 ` Charles C. Berry
2016-05-29 12:31 ` Vikas Rawal
2016-05-29 13:13 ` Vikas Rawal [this message]
2016-05-29 17:58 ` Charles C. Berry
2016-05-30 0:37 ` Vikas Rawal
2016-05-30 1:18 ` Charles C. Berry
2016-05-30 10:24 ` Vikas Rawal
2016-05-30 16:22 ` Charles C. Berry
2016-05-29 2:02 ` Vikas Rawal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5F862231-C04A-4BF6-8A2A-2377AF000374@agrarianresearch.org \
--to=vikaslists@agrarianresearch.org \
--cc=ccberry@ucsd.edu \
--cc=emacs-orgmode@gnu.org \
--cc=wtd@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.