A helper function for encoding and compressing a file or string to ASCII using base91_encode() and qserialize() with the highest compression level.

encode_source(x = NULL, file = NULL, width = 120)

Arguments

x

The object to encode (if file is not NULL)

file

The file to encode (if x is not NULL)

width

The output will be broken up into individual strings, with width being the longest allowable string.

Value

A character vector in base91 representing the compressed original file or object.

Details

The encode_source() and decode_source() functions are useful for storing small amounts of data or text inline to a .R or .Rmd file.

Examples

set.seed(1); data <- sample(500)
result <- encode_source(data)
# Note: the result string is not guaranteed to be consistent between qs or zstd versions
#       but will always properly decode regardless
print(result)
#> [1] "un]'BAAA@QRtHACAAAAAAAAAUAAA+:g6JiSTn^EA[~]'!AV3Sc;;>n~`ikHh)Dx<E]9Z{7;Z@!zeJzr}`wC/54h7U,#i5TSo^t3q<R8KFf{n!r9]sjBP')H7"
#> [2] "oBXM}D12Zq&k:~[]^..:DH()$]$m4UIZ2|p<MT!ui&JL{wAU_6>6},3'R993XmOga`+;Hj4d1)'G!:S}f?}o[[:AMpLV8[Xh)KdKhs+]cw~47^fMr}ans/8,"
#> [3] "z83mJu4{|&'k=a{Gk|/lk1sc&u[niF5u3.=mGJ.vKToW;f*#x~VinZ.!M)/:wf4KbZ,J(l)6~?ime]:V[J?Gcojwo_/3,)G0Z?cfb0cH],L5j<4kz~'%.6I#"
#> [4] ":[8a,aI;p)2J}x:Nqj1E$8YYqIwL}ay*a=@{Sg|`:l)(kQ6dPY4kpeK!:AFq.i]Ee*rV4b~P:)doni?KBn{'Ny*@0C>I5WcGy>{PPB|*pU%>~%?+cSd'ia@I"
#> [5] "OgW!nJc}@g*_YzT@v7./OF,@[l'yD_vixDo&P|2uJx%tnYh#'];%Tilet$z<,BrCl75NgS4ksmz9^E1&#Q1o3,?/evO3>&ciSCr/|;]90'Hhr1g}+2(~,bev"
#> [6] "hL:1gspVI*4DOcl+v_zR2u'#2JD=(d?5z6$bv(C@}pS1vdxxY`69n1Kr~_{QHABtAAAAv(ccN&}~MJ5*v7u0Qtz(EZb]weH_B'<Jr|ao,_mJcvzojt&eh&$1"
#> [7] "xItVQE.{=2xD^WQDz|zp?%Xq>^$8d)vxKtm$9q6|McPk:YPE__<SA_UB~|=L$tVbsja3;tlAK^>[nhKhLD2:2%4'2so4A!@u/~A"                     
result <- decode_source(result) # [1]  1  2  3  4  5  6  7  8  9 10