A helper function for encoding and compressing a file or string to ASCII using base91_encode() and qs_serialize() with the highest compression level.
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] "unjXVBZLQAAAAAAAAA!mM.Q[z.jU..CAC'><F{C^nCj!C'(L>cYAAAlBVtAADHMA[t2cg7)TNAAA^|AAuWm:wwVr~EY>Ebk8&4GgXK~[A;&ZL$daNod(i!iU"
#> [2] "1d9SP%<a|YwbA!I_&Y<X6l*^Tn2&{,j*4INp`h,MY?1`..=8'~Ks5<fJ7?J<<g=xek[kT(:%jC<F/e])LzAZi04#X%dLc8mk02xe<}`Sa<]dNR)B!#EW<TWK"
#> [3] "s%DtzU03;o5QjyPyQWjpP*sc<{QzW~7$)[<@a;c$EXd}rhu#mNsw#r^##aWOhX|$#vd)c[n$xx])yJUL^P@f,~KR%MkfH?l]*PcF7M[E?Sid'nRTQ{]K|xnD"
#> [4] "P%RYUq^.jiDa7_88O,8w{j0/RmcS.~'gl:y<]of6k6y]V?/x'*^z(!aCgeMMWx*Ft6,?6morJQ'|^#?hT1;7HMd#UPFfn'CVkRqv8i)3/N'Hm?P%U!nFuTrt"
#> [5] "Ny*@0C>I5WcGy>{PPB|*pU%>~%?+cSd'ia@IOgW!nJc}@g*_YzT@v7./OF,@[l'yD_vixDo&P|2uJx%tnYh#'];%Tilet$z<,BrCl75NgS4ksmz9^E1&#Q1o"
#> [6] "3,?/evO3>&ciSCr/|;]90'Hhr1g}+2(~,bevhL:1gspVI*4DOcl+v_zR2u'#2JD=(d?5z6$bv(C@}pS1vdxxY`69n1Kr~_rBAA@@AA5F:qdvW>z[`_;=AAMS"
#> [7] "O:D!L~zWc?(>/e;*rS:vM*v4%CkfYS[}x:V2?k$p0;Mp'I=IfSuTrWlkI63Y+(Ka%=&cUxm;(^[=|v+5nlB1Pw2B{o3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