A helper function for encoding and compressing a file or string to ASCII using base91_encode() and qs_serialize() with the highest compression level.
encode_source(x = NULL, file = NULL, width = 120)A character vector in base91 representing the compressed original file or object.
The encode_source() and decode_source() functions are useful for storing small amounts of data or text inline to a .R or .Rmd file.
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] "unjXVBZLQAAAAAAAAALv7!1rRTkKK,CAC'><F{C^nC{9C'9L>cYAAAlBRtAADHMA[t2cg7)Tl4PAAAV3Sc;;>n~`ikHh)Dx<E]9Z{7;Z@!zeJzr}`wC/54h7"
#> [2] "U,#i5TSo^t3q<R8KFf{n!r9]sjBP')H7oBXM}D12Zq&k:~[]^..:DH()$]$m4UIZ2|p<MT!ui&JL{wAU_6>6},3'R993XmOga`+;Hj4d1)'G!:S}f?}o[[:A"
#> [3] "MpLV8[Xh)KdKhs+]cw~47^fMr}ans/8,z83mJu4{|&'k=a{Gk|/lk1sc&u[niF5u3.=mGJ.vKToW;f*#x~VinZ.!M)/:wf4KbZ,J(l)6~?ime]:V[J?Gcojw"
#> [4] "o_/3,)G0Z?cfb0cH],L5j<4kz~'%.6I#:[8a,aI;p)2J}x:Nqj1E$8YYqIwL}ay*a=@{Sg|`:l)(kQ6dPY4kpeK!:AFq.i]Ee*rV4b~P:)doni?KBn{'Ny*@"
#> [5] "0C>I5WcGy>{PPB|*pU%>~%?+cSd'ia@IOgW!nJc}@g*_YzT@v7./OF,@[l'yD_vixDo&P|2uJx%tnYh#'];%Tilet$z<,BrCl75NgS4ksmz9^E1&#Q1o3,?/"
#> [6] "evO3>&ciSCr/|;]90'Hhr1g}+2(~,bevhL:1gspVI*4DOcl+v_zR2u'#2JD=(d?5z6$bv(C@}pS1vdxxY`69n1Kr~_rBAA@@AA5F'q:Y3ro^Lw,enCXL7)jm"
#> [7] "5l=Q;vF_|.qz!Y]}pbnhW>=c#|!RB'uyzJ86g3N4(RENktJnvs:nXd'gZB]cP/;x:QX#/nwp8LFz|5BgcGSD%/SRma2(.7lFYOc*IC.k{/UcLw'6cP$jwRga"
#> [8] "L_<7L|{!C2sTS3c%*|W[SOdqDSfiY)c~EkVt?m#bIf5DX+,$yB_aPPL~DYseTi^hJ/M}Ke"
result <- decode_source(result) # [1] 1 2 3 4 5 6 7 8 9 10