treatssyntaxhighlighter

syntaxhighlighter  时间:2021-05-18  阅读:()
knitr:AGeneral-PurposeToolforDynamicReportGenerationinRYihuiXieJanuary6,2013Theoriginalparadigmofliterateprogrammingwasbroughtforwardmainlyforsoftwaredevelopment,orspecically,tomixsourcecode(forcomputer)anddocumentation(forhuman)together.
EarlysystemsincludeWEBandNoweb;Sweave(Leisch,2002)wasderivedfromthelatter,butitislessfocusedondocumentingsoftware,insteaditismainlyusedforreproducibledataanalysisandgeneratingstatisticalreports.
Theknitrpackage(Xie,2012c)isfollowingthestepsofSweave.
Forthismanual,IassumereadershavesomebackgroundknowledgeofSweavetounderstandthetechnicaldetails;forareferenceofavailableoptions,hooksanddemos,seethepackagehomepagehttp://yihui.
name/knitr/.
1HelloWorldAnaturalquestioniswhytoreinventthewheel.
TheshortansweristhatextendingSweavebyhackingSweaveDrivers.
Rintheutilspackageisadifcultjobtome.
Manyfeaturesinknitrcomenaturallyasuserswouldhaveexpected.
Figure1isasimpledemoofsomefeaturesofknitr.
IwouldhavechosentohidetheRcodeifthiswerearealreport,buthereIshowthecodejustforthesakeofdemonstration.
Ifwetypeqplot()inR,wegetaplot,andthesamethinghappensinknitr.
Ifwefitxx[1]-0.
630160.
12716-1.
100260.
07677-0.
10064>var(x)[1]0.
2776Theexamplebelowshowstheeffectoftidy=TRUE/FALSE:##optiontidy=FALSEfor(kin1:10){j=cos(sin(k)*k2)+3;print(j-5)}##optiontidy=TRUEfor(kin1:10){j>=@DifferentdocumentscanreadthesameRscript,sotheRcodecanbereusableacrossdifferentinputdocuments.
3.
5EvaluationofChunkOptionsBydefaultknitrusesanewsyntaxtoparsechunkoptions:ittreatsthemasfunctionargumentsinsteadofatextstringtobesplittoobtainoptionvalues.
Thisgivestheusermuchmorepowerthantheoldsyntax;wecanpassarbitraryRobjectstochunkoptionsbesidessimpleoneslikeTRUE/FALSE,numbersandcharacterstrings.
Thepagehttp://yihui.
name/knitr/demo/sweave/hasgiventwoexamplestoshowtheadvantagesofthenewsyntax.
Hereweshowyetanotherusefulapplication.
Beforeknitr0.
3,therewasafeaturenamed"conditionalevaluation"6.
Theideais,insteadofsettingchunkoptionsevalandechotobeTRUEorFALSE(constants),theirvaluescanbecontrolledbyglobalvariablesinthecurrentRsession.
Thisenablesknitrtoconditionallyevaluatecodechunksaccordingtovariables.
Forexample,hereweassignTRUEtoavariabledothis:dothis<-TRUEInthenextchunk,wesetchunkoptionseval=dothisandecho=!
dothis,botharevalidRexpressionssincethevariabledothisexists.
Aswecansee,thesourcecodeishidden,butitwasindeedevaluated:##[1]"youcannotseemysourcebecause!
dothisisFALSE"Thenweseteval=dothisandecho=dothisforanotherchunk:dothis##[1]TRUEIfwechangethevalueofdothistoFALSE,neitheroftheabovechunkswillbeevaluatedanymore.
Thereforewecancontrolmanychunkswithasinglevariable,andpresentresultsselectively.
Thisoldfeaturerequiresknitrtotreatevalandechospecially,andwecaneasilyseethatitisnolongernecessarywiththenewsyntax:eval=dothiswilltellRtondthevariabledothisautomaticallyjustlikewecallafunctionfoobar(eval=dothis).
Whatismore,alloptionswillbeevaluatedasRexpressionsunlesstheyarealreadyconstantswhichdonotneedtobeevaluated,sothisoldfeaturehasbeengeneralizedtoallotheroptionsnaturally.
3.
6CustomizationTheknitrpackageisreadyforcustomization.
Boththepatternsandhookscanbecustomized;seethepackagewebsitefordetails.
HereIshowanexampleonhowtosaverglplots(AdlerandMurdoch,2012)usingacustomizedhookfunction.
Firstwedeneahooknamedrglusingthefunctionhookrgl()inknitr:6requestfromhttps://plus.
google.
com/u/0/116405544829727492615/posts/43WrRUffjzK9knit_hooks$set(rgl=hook_rgl)head(hook_rgl)#thehookfunctionisdefinedasthis####1function(before,options,envir)##2{##3library(rgl)##4if(before||rgl.
cur()==0)##5return()##6name=fig_path()Thenweonlyhavetosetthechunkoptionrgl=TRUE:library(rgl)demo("bivar",package="rgl",echo=FALSE)par3d(zoom=0.
7)Duetotheexibilityofoutputhooks,knitrsupportsseveraldifferentoutputformats.
Theimplemen-tationisfairlyeasy,e.
g.
,forLATEXweputRoutputinverbatimenvironments,andinHTML,itisonlyamatterofputtingoutputindivlayers.
Thesearesimplycharacterstringoperations.
Manydemosinhttp://yihui.
name/knitr/demosshowthisideaclearly.
Thismanualdidnotcoverallthefeaturesofknitr,andusersareencouragedtothumbthroughthewebsitetoknowmorepossiblefeatures.
4EditorsYoucanuseanytexteditorstowritethesourcedocuments,butsomehavebuilt-insupportforknitr.
BothRStudio(http://www.
rstudio.
org)andLYX(http://www.
lyx.
org)havefullsupportforknitr,andyoucancompilethedocumenttoPDFwithjustoneclick.
Seehttp://yihui.
name/knitr/demo/rstudio/andhttp://yihui.
name/knitr/demo/lyx/respectively.
ItisalsopossibletosupportothereditorslikeEclipse,TexmakerandWinEdt;seethedemolistinthewebsiteforcongurationinstructions.
AboutThisDocumentThismanualwaswritteninLYXandcompiledwithknitr(version0.
9.
5).
TheLYXsourceandtheRnwdocumentexportedfromLYXcanbefoundunderthesedirectories:system.
file("examples","knitr-manual.
lyx",package="knitr")#lyxsourcesystem.
file("examples","knitr-manual.
Rnw",package="knitr")#Rnwsource10Youcanusethefunctionknit()toknittheRnwdocument(remembertoputthetwo.
biblesunderthesamedirectory),andyouneedtomakesurealltheRpackagesusedinthisdocumentareinstalled:install.
packages(c("animation","rgl","tikzDevice","ggplot2"))Feedbackandcommentsonthismanualandthepackagearealwayswelcome.
Bugreportsandfeaturerequestscanbesenttohttps://github.
com/yihui/knitr/issues,andquestionscanbedeliveredtothemailinglisthttps://groups.
google.
com/group/knitr.
ReferencesAdlerD,MurdochD(2012).
rgl:3Dvisualizationdevicesystem(OpenGL).
Rpackageversion0.
92.
894,URLhttp://CRAN.
R-project.
org/package=rgl.
BrackenC,SharpsteenC(2012).
pgfSweave:QualityspeedygraphicscompilationandcachingwithSweave.
Rpackageversion1.
3.
0,URLhttp://CRAN.
R-project.
org/package=pgfSweave.
FrancoisR(2012).
highlight:Syntaxhighlighter.
Rpackageversion0.
3.
2,URLhttp://CRAN.
R-project.
org/package=highlight.
LeischF(2002).
"Sweave:DynamicGenerationofStatisticalReportsUsingLiterateDataAnalysis.
"InCOMPSTAT2002ProceedingsinComputationalStatistics,69,pp.
575–580.
PhysicaVerlag,Heidelberg.
PengRD(2012).
cacheSweave:ToolsforcachingSweavecomputations.
Rpackageversion0.
6-1,URLhttp://CRAN.
R-project.
org/package=cacheSweave.
SharpsteenC,BrackenC(2012).
tikzDevice:ADeviceforRGraphicsOutputinPGF/TikZFormat.
Rpackageversion0.
6.
2,URLhttp://CRAN.
R-project.
org/package=tikzDevice.
WickhamH(2012).
evaluate:Parsingandevaluationtoolsthatprovidemoredetailsthanthedefault.
Rpackageversion0.
4.
3.
XieY(2012a).
animation:Agalleryofanimationsinstatisticsandutilitiestocreateanimations.
Rpackageversion2.
1.
1,URLhttps://github.
com/yihui/animation.
XieY(2012b).
formatR:FormatRCodeAutomatically.
Rpackageversion0.
7,URLhttp://yihui.
name/formatR.
XieY(2012c).
knitr:Ageneral-purposepackagefordynamicreportgenerationinR.
Rpackageversion0.
9,URLhttp://yihui.
name/knitr/.
11

HostKvm5.95美元起,香港、韩国可选

HostKvm发布了夏季特别促销活动,针对香港国际/韩国机房VPS主机提供7折优惠码,其他机房全场8折,优惠后2GB内存套餐月付仅5.95美元起。这是一家成立于2013年的国外主机服务商,主要提供基于KVM架构的VPS主机,可选数据中心包括日本、新加坡、韩国、美国、中国香港等多个地区机房,均为国内直连或优化线路,延迟较低,适合建站或者远程办公等。下面分享几款香港VPS和韩国VPS的配置和价格信息。...

ThomasHost(月付5美元)美国/法国/英国/加拿大KVM,支持Windows

ThomasHost域名注册自2012年,部落最早分享始于2016年,还算成立了有几年了,商家提供基于KVM架构的VPS,数据中心包括美国、法国、英国、加拿大和爱尔兰等6个地区机房,VPS主机套餐最低2GB内存起步,支持Windows或者Linux操作系统,1Gbps端口不限制流量。最近商家提供了一个5折优惠码,优惠后最低套餐月付5美元起。下面列出部分套餐配置信息。CPU:1core内存:2GB硬...

spinservers:圣何塞物理机7.5折,$111/月,2*e5-2630Lv3/64G内存/2T SSD/10Gbps带宽

spinservers美国圣何塞机房的独立服务器补货120台,默认接入10Gbps带宽,给你超高配置,这价格目前来看好像真的是无敌手,而且可以做到下单后30分钟内交货,都是预先部署好了的。每一台机器用户都可以在后台自行安装、重装、重启、关机操作,无需人工参与! 官方网站:https://www.spinservers.com 比特币、信用卡、PayPal、支付宝、webmoney、Payssi...

syntaxhighlighter为你推荐
仪器win7支持ipad化学品安全技术说明书C1:山东品牌商品馆重庆宽带测速重庆联通宽带测速的网址是好多呢?ipad连不上wifiipad显示无互联网连接怎么回事?windows键是哪个Windows快捷键是什么tcpip上的netbios怎么启用TCP/IP上的NetBIOSx-routerx-arcsinx的等价无穷小是什么?360chrome360浏览器和谷歌chrome比哪个好用
域名拍卖 合租服务器 域名备案信息查询 主机优惠码 a2hosting 512av 56折 Hello图床 火车票抢票攻略 发包服务器 南通服务器 电信虚拟主机 多线空间 raid10 帽子云排名 贵阳电信 阿里云邮箱登陆地址 apnic winds 美国主机 更多