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

小白云 (80元/月),四川德阳 4核2G,山东枣庄 4核2G,美国VPS20元/月起三网CN2

小白云是一家国人自营的企业IDC,主营国内外VPS,致力于让每一个用户都能轻松、快速、经济地享受高端的服务,成立于2019年,拥有国内大带宽高防御的特点,专注于DDoS/CC等攻击的防护;海外线路精选纯CN2线路,以确保用户体验的首选线路,商家线上多名客服一对一解决处理用户的问题,提供7*24无人全自动化服务。商家承诺绝不超开,以用户体验为中心为用提供服务,一直坚持主打以产品质量用户体验性以及高效...

Dataideas:$1.5/月KVM-1GB/10G SSD/无限流量/休斯顿(德州)_主机域名

Dataideas是一家2019年成立的国外VPS主机商,提供基于KVM架构的VPS主机,数据中心在美国得克萨斯州休斯敦,主机分为三个系列:AMD Ryzen系列、Intel Xeon系列、大硬盘系列,同时每个系列又分为共享CPU和独立CPU系列,最低每月1.5美元起。不过需要注意,这家没有主页,你直接访问根域名是空白页的,还好他们的所有套餐支持月付,相对风险较低。下面以Intel Xeon系列共...

青果网络-618阿里云,腾讯云特惠优惠折上折!

官方网站:点击访问青果云官方网站活动方案:—————————–活动规则—————————1、选购活动产品并下单(先不要支付)2、联系我司在线客服修改价格或领取赠送时间3、确认价格已按活动政策修改正确后,支付订单,到此产品开设成功4、本活动产品可以升级,升级所需费用按产品原价计算若发生退款,按资源实际使用情况折算为产品原价再退还剩余余额! 美国洛杉矶CN2_GIACPU内存系统盘流量宽带i...

syntaxhighlighter为你推荐
中断fastreport2excursionsios5思科route请务必阅读正文之后的免责条款部分lowercasecss模块ios8支持ipad支持ipad支持ipad支持ipad
vps是什么 google电话 iisphpmysql 国内php空间 193邮箱 刀片式服务器 100mbps 吉林铁通 服务器硬件配置 大化网 卡巴斯基试用版下载 小夜博客 googlevoice 石家庄服务器 美国asp空间 windowsserver2008r2 blaze 电脑主机启动不了 主机之家 qq空间申请关闭 更多