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] "unjXVBZLQAAAAAAAAAdZs=lE4D`Y9>CAC'><F{C^nC.#C'AM>cYAKCEAY4FBGOAAC'2cg7)TNAAA^|AAuWm:wwVr~EY>Ebk8&4GgXK~[A;&ZL$daNod(i!iU"
#> [2] "1d9SP%KAAAG{R0~5iav9Q0KHKkVF}*DV*8eExAbuAg}kVk9CIFs^Rq|]C1btFnMkx)!d%]kMPQj.v151g`]jDKQ`T^40^Shtv0BS8=T5&>~_RFp)(|sI@#Xl"
#> [3] "?LBU9H3rpDQK2a<Z78RH1!Q#OCa`wy_,(>Tsd[|KL[;x,O6Tt2EQR?BY@)0^<t;nn%a6/a;VVW,@``TQ@[=W07LdDABt&H<uqO}J!ar2@?9su&8#/npTA:D5"
#> [4] "J?X)@T,OF2:'l{OKu4IEt+c6u6Hj_GA,_Wh{@=ZU72lYDABtfBAAn72O7%/T|itRsj!P1t1HxZcM|)4O{TPghhx,'V'8r1bNr]Cwem:wYe4(v3$1&Xf!?b^z"
#> [5] "Ax$n1gKf&v)J)(H+ioaBoxcLODa_}H3''n5.9TAn&!I.0WRNoEHQLf%EOsp9j|6+Jo+:][1vjo{Su+C|XR+BUh1rbXyY?(TM!ftp_=K!T8X=Zm]tVB$d:GQJ"
#> [6] "cSWT.;qvb>g1aU/j{[9)0bnhORJB(k']{eatHhr1g}+2(~,bevhL:1gspVI*4DOcl+v_zR2u'#2JD=(d?5z6$bv(C@}pS1vdxxY`69n1Kr~_rBAA@@AA5FKq"
#> [7] "dv@g:1O4_v[]GAT3|8gB6]3TP|>gA]6/AJY>Xk%hI>C(~/{Z|%`&x6]Ekxd{e%V<sqI}@)O;oCzP+gSR>k(y}fm1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