<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Darwin Cubi — Writing</title>
<link>https://darwincubi.rbind.io/blog.html</link>
<atom:link href="https://darwincubi.rbind.io/blog.xml" rel="self" type="application/rss+xml"/>
<description>Darwin Cubi is an MLOps and Production ML Engineer specialized in credit risk, pricing, underwriting, insurance analytics, and financial machine learning systems.</description>
<generator>quarto-1.9.38</generator>
<lastBuildDate>Wed, 02 Mar 2022 00:00:00 GMT</lastBuildDate>
<item>
  <title>How to create a CV with Rmarkdown, Awesome CV and Google Sheets</title>
  <link>https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/</link>
  <description><![CDATA[ 
Skip to main content
<script>
  document.body.prepend(document.querySelector(".skip-link"));
</script>




<section id="cv-in-r" class="level3">
<h3 class="anchored" data-anchor-id="cv-in-r">CV in R</h3>
<p>When entering the working world or looking for new job opportunities we have all been in the task of creating or updating our resume and almost always the main tool is Word, Canva or Adobe Illustrator (for the more advanced). The last two options, although they offer a lot of customization in terms of design, do not allow much flexibility when updating information or easily adapting to a workflow. On the other hand, Word has templates with somewhat bland designs and the constant struggle with alignments, indents and styles when entering new information.</p>
<p>A couple of years ago I was confronted with this problem and I was lucky to find the solution in the vitae package developed by <a href="https://github.com/mitchelloharawild/vitae"><strong>Mitchell O’Hara-Wild</strong></a>. This package allows you to create a cv with 6 types of formatting:</p>
<ol type="1">
<li>Awesome-CV format</li>
<li>Hydman</li>
<li>ModernCV</li>
<li>Twenty seconds</li>
<li>latexcv</li>
<li>markdown-cv</li>
</ol>
<p><a href="https://github.com/mitchelloharawild/vitae#examples-of-using-vitae">Here</a> you can see the examples of the different formats together with their source code. Personally I like the Awesome-CV template and in fact this whole tutorial is developed focused on this style of cv.</p>
<p>First you must create a project in Rstudio because we will take advantage of git version control, in this <a href="https://www.geo.uzh.ch/microsite/reproducible_research/post/rr-rstudio-git/#:~:text=In%20RStudio%20Select%20File%20%3E%20New,repository%20to%20your%20project%20folder">link</a> you can find the step by step of how to create a project with git version control.</p>
<p>The first step is to install the vitae package</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vitae"</span>)</span></code></pre></div></div>
<p>and then create an awesome cv template with markdown</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic1.png" loading="lazy" decoding="async" alt="RStudio menu for creating a new R Markdown document" width="792" height="658"> <img src="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic2.png" loading="lazy" decoding="async" alt="R Markdown template dialog with the Awesome CV format selected" width="1188" height="1036"> This will create the following template</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic3.png" loading="lazy" decoding="async" alt="RStudio editor showing Awesome CV YAML parameters and example entries" width="1382" height="834"> To compile you must click on ‘Knit’ and you will have the following pdf</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic4.png" loading="lazy" decoding="async" alt="Rendered Awesome CV example for Marie Curie" width="1078" height="830"> In the YAML parameters you can specify data such as name, position, address, email, etc. <a href="https://cran.r-project.org/web/packages/vitae/vignettes/vitae.html">Here</a> you can find more details about each available parameter.</p>
<p>The data for the cv is entered in a tribble and transformed to awesome format with the <code>detailed_entries()</code> function that has the parameters:</p>
<ul>
<li>data: tribble, tibble or dataframe with the data</li>
<li>what: name of the activity or title</li>
<li>when: date of the activity or title</li>
<li>with: company or institution</li>
<li>where: place of the activity or title</li>
<li>why : for additional data (this can be a list of values)</li>
</ul>
<p>There is also function <code>brief_entries(data, what, when, with, .protect = TRUE)</code> which is similar but with less arguments. For more information about these functions you can type in the console <code>?detailed_entries</code> or <code>?brief_entries</code>.</p>
<p>The following code</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb2-2">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Degree, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Year, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Institution, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Where,</span>
<span id="cb2-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Informal studies"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1889-91"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flying University"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warsaw, Poland"</span>,</span>
<span id="cb2-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Physics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1893"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span>,</span>
<span id="cb2-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Mathematics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1894"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span></span>
<span id="cb2-6">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detailed_entries</span>(Degree, Year, Institution, Where)</span></code></pre></div></div>
</div>
<p>compiling to pdf will create</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic5.png" loading="lazy" decoding="async" alt="Rendered education entries generated from structured R data" width="993" height="191"> At this point you will have created a functional cv and will not need to worry about layout, indentation or text alignment. But it is still cumbersome to have the data and the code in the same place. To solve this problem I took the workflow from the <a href="http://nickstrayer.me/datadrivencv/">datadrivencv</a> package created by <a href="https://github.com/nstrayer">Nick Strayer</a> as a basis.</p>
</section>
<section id="save-your-data-in-google-sheets" class="level3">
<h3 class="anchored" data-anchor-id="save-your-data-in-google-sheets">Save your data in Google sheets</h3>
<p>We will use the <code>googlesheets4</code> package to download the cv data from a google spreadsheet. I suggest copying my <a href="https://docs.google.com/spreadsheets/d/1AN85IIvbcMnGbcOCX3jurB4fMOp_niAUbDBU_zfjFEw/edit?usp=sharing">sheet</a> and replacing its data.</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic6.png" loading="lazy" decoding="async" alt="Google Sheets workbook containing structured CV entries" width="1317" height="805"> The document has the following:</p>
<ol type="1">
<li>entries: information about education, work experience, certifications, etc.</li>
<li>language_skills: tools or skills you have.</li>
<li>post_info: information about post.</li>
<li>text_block: additional information such as your professional description or interests.</li>
<li>contact_info: contact information (email, phone, etc).</li>
</ol>
</section>
<section id="create-custom-functions" class="level3">
<h3 class="anchored" data-anchor-id="create-custom-functions">Create custom functions</h3>
<p>The following function allows to create an object with all the information of the spreadsheet,</p>
<ol type="1">
<li>data_location: is the link of the spreadsheet from google sheet</li>
<li>pdf_mode: if TRUE the text links are removed.</li>
<li>sheet_is_publicly_readable: TRUE if the link to the spreadsheet is public.</li>
</ol>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb3-1">create_CV_object <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data_location,</span>
<span id="cb3-2">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_mode =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb3-3">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_is_publicly_readable =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) {</span>
<span id="cb3-4">  </span>
<span id="cb3-5">  cv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb3-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_mode =</span> pdf_mode,</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>()</span>
<span id="cb3-8">  )</span>
<span id="cb3-9">  </span>
<span id="cb3-10">  is_google_sheets_location <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"docs</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.google</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.com"</span>)</span>
<span id="cb3-11">  </span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(is_google_sheets_location){</span>
<span id="cb3-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(sheet_is_publicly_readable){</span>
<span id="cb3-14">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This tells google sheets to not try and authenticate. Note that this will only</span></span>
<span id="cb3-15">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># work if your sheet has sharing set to "anyone with link can view"</span></span>
<span id="cb3-16">      googlesheets4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gs4_deauth</span>()</span>
<span id="cb3-17">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb3-18">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># My info is in a public sheet so there's no need to do authentication but if you want</span></span>
<span id="cb3-19">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to use a private sheet, then this is the way you need to do it.</span></span>
<span id="cb3-20">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># designate project-specific cache so we can render Rmd without problems</span></span>
<span id="cb3-21">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gargle_oauth_cache =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".secrets"</span>)</span>
<span id="cb3-22">    }</span>
<span id="cb3-23">    </span>
<span id="cb3-24">    read_gsheet <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(sheet_id){</span>
<span id="cb3-25">      googlesheets4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sheet</span>(data_location, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet =</span> sheet_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>)</span>
<span id="cb3-26">    }</span>
<span id="cb3-27">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"entries"</span>)</span>
<span id="cb3-28">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>skills        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"language_skills"</span>)</span>
<span id="cb3-29">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text_blocks   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text_blocks"</span>)</span>
<span id="cb3-30">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>contact_info  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contact_info"</span>)</span>
<span id="cb3-31">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post_info  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post_info"</span>)</span>
<span id="cb3-32">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb3-33">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Want to go old-school with csvs?</span></span>
<span id="cb3-34">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"entries.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-35">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>skills       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"language_skills.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-36">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text_blocks  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text_blocks.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-37">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>contact_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contact_info.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-38">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post_info.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-39">  }</span>
<span id="cb3-40">  </span>
<span id="cb3-41">  </span>
<span id="cb3-42">  extract_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(dates){</span>
<span id="cb3-43">    date_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(dates, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(20|19)[0-9]{2}"</span>)</span>
<span id="cb3-44">    date_year[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(date_year)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year</span>(lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ymd</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.Date</span>())) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb3-45">    </span>
<span id="cb3-46">    date_year</span>
<span id="cb3-47">  }</span>
<span id="cb3-48">  </span>
<span id="cb3-49">  parse_dates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(dates){</span>
<span id="cb3-50">    </span>
<span id="cb3-51">    date_month <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(dates, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">w+|</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)(?=(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">s|</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/|-)(20|19)[0-9]{2})"</span>)</span>
<span id="cb3-52">    date_month[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(date_month)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span></span>
<span id="cb3-53">    </span>
<span id="cb3-54">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>, date_month, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_year</span>(dates), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-55">      lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dmy</span>()</span>
<span id="cb3-56">  }</span>
<span id="cb3-57">  </span>
<span id="cb3-58">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Clean up entries dataframe to format we need it for printing</span></span>
<span id="cb3-59">  cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&lt;&gt;%</span></span>
<span id="cb3-60">    tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unite</span>(</span>
<span id="cb3-61">      tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">starts_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'description'</span>),</span>
<span id="cb3-62">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description_bullets"</span>,</span>
<span id="cb3-63">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- "</span>,</span>
<span id="cb3-64">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb3-65">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-66">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">description_bullets =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(description_bullets , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- "</span>)) ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-67">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb3-68">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># description_bullets = ifelse(description_bullets != "", paste0("- ", description_bullets), ""),</span></span>
<span id="cb3-69">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NULL"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, start),</span>
<span id="cb3-70">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NULL"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, end),</span>
<span id="cb3-71">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start_year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_year</span>(start),</span>
<span id="cb3-72">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_year</span>(end),</span>
<span id="cb3-73">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">no_start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(start),</span>
<span id="cb3-74">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">has_start =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>no_start,</span>
<span id="cb3-75">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">no_end =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(end),</span>
<span id="cb3-76">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">has_end =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>no_end,</span>
<span id="cb3-77">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">timeline =</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb3-78">        no_start  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> no_end  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"N/A"</span>,</span>
<span id="cb3-79">        no_start  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> has_end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(end),</span>
<span id="cb3-80">        has_start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> no_end  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Current"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, start),</span>
<span id="cb3-81">        <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>                <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(end, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, start)</span>
<span id="cb3-82">      )</span>
<span id="cb3-83">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-84">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parse_dates</span>(end))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-85">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate_all</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(.), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'N/A'</span>, .))</span>
<span id="cb3-86">  </span>
<span id="cb3-87">  cv</span>
<span id="cb3-88">}</span></code></pre></div></div>
</div>
<p>This function removes links from a text</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1">sanitize_links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv, text){</span>
<span id="cb4-2">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pdf_mode){</span>
<span id="cb4-3">    link_titles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract_all</span>(text, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[).+?(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">])'</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb4-4">    link_destinations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract_all</span>(text, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">().+?(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">))'</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb4-5">    </span>
<span id="cb4-6">    n_links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>links)</span>
<span id="cb4-7">    n_new_links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(link_titles)</span>
<span id="cb4-8">    </span>
<span id="cb4-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(n_new_links <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>){</span>
<span id="cb4-10">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add links to links array</span></span>
<span id="cb4-11">      cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>links, link_destinations)</span>
<span id="cb4-12">      </span>
<span id="cb4-13">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Build map of link destination to superscript</span></span>
<span id="cb4-14">      link_superscript_mappings <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_names</span>(</span>
<span id="cb4-15">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;sup&gt;"</span>, (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_new_links) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n_links, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;/sup&gt;"</span>),</span>
<span id="cb4-16">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"("</span>, link_destinations, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>)</span>
<span id="cb4-17">      )</span>
<span id="cb4-18">      </span>
<span id="cb4-19">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Replace the link destination and remove square brackets for title</span></span>
<span id="cb4-20">      text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> text <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-21">        stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fixed</span>(link_superscript_mappings)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-22">        stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[(.+?)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">]'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">1"</span>)</span>
<span id="cb4-23">    }</span>
<span id="cb4-24">  }</span>
<span id="cb4-25">  </span>
<span id="cb4-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> cv, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> text)</span>
<span id="cb4-27">}</span></code></pre></div></div>
</div>
<p>You also need functions to print the downloaded data.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print text block</span></span>
<span id="cb5-2">print_text_block <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv, label){</span>
<span id="cb5-3">  text_block <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text_blocks, loc <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> label) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-4">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(text)</span>
<span id="cb5-5">  </span>
<span id="cb5-6">  strip_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sanitize_links</span>(cv, text_block)</span>
<span id="cb5-7">  </span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(strip_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text)</span>
<span id="cb5-9">  </span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(strip_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cv)</span>
<span id="cb5-11">}</span>
<span id="cb5-12"></span>
<span id="cb5-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print table of skills</span></span>
<span id="cb5-14">print_skill <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv){</span>
<span id="cb5-15">  </span>
<span id="cb5-16">  glue_template <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-17"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">cvskill{&lt;&lt;group&gt;&gt;}{&lt;&lt;skills&gt;&gt;}"</span></span>
<span id="cb5-18">  </span>
<span id="cb5-19">  skills_formatted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>skills <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(details)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>details<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{skill}"</span>), glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{skill} ({details})"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skills =</span> glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_collapse</span>(skill, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>)) </span>
<span id="cb5-23">  </span>
<span id="cb5-24">  cv_skill <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> skills_formatted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-25">    glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_data</span>(glue_template, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.open =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;&lt;"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.close =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;&gt;"</span> ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)</span>
<span id="cb5-27">  </span>
<span id="cb5-28">  cv_skill_env <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">begin{cvskills}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>, cv_skill, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">end{cvskills}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span> , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)</span>
<span id="cb5-29">  </span>
<span id="cb5-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(cv_skill_env)</span>
<span id="cb5-31">  </span>
<span id="cb5-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(cv)</span>
<span id="cb5-33">}</span>
<span id="cb5-34"></span>
<span id="cb5-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print table of posts</span></span>
<span id="cb5-36">print_post<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">glue_template =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"default"</span>){</span>
<span id="cb5-37">  </span>
<span id="cb5-38">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(glue_template <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"default"</span>){</span>
<span id="cb5-39">    glue_template <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- [{name}]({link})</span></span>
<span id="cb5-41"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-42">  }  </span>
<span id="cb5-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_data</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post_info , glue_template))</span>
<span id="cb5-44">  </span>
<span id="cb5-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(cv)</span>
<span id="cb5-46">}</span></code></pre></div></div>
</div>
<p>Okay, now let’s replace</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>opts_chunk<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">echo =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warning =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(vitae)</span></code></pre></div></div>
</div>
<p>with this, so we can use the previous functions</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb7-1">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>opts_chunk<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">echo =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warning =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(vitae)</span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb7-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(magrittr)</span>
<span id="cb7-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Utils/data_download_funs.R"</span>)</span>
<span id="cb7-6"></span>
<span id="cb7-7">CV <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_CV_object</span>(</span>
<span id="cb7-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://docs.google.com/spreadsheets/d/19YWFjpiCqTbrwrU1hpxDNubZKoNi-o0DvOQbcHqsc7c/edit?usp=sharing"</span>,  </span>
<span id="cb7-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_mode =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb7-10">)</span></code></pre></div></div>
</div>
<p>For the Education section we can replace</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tibble)</span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb8-3">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Degree, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Year, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Institution, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Where,</span>
<span id="cb8-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Informal studies"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1889-91"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flying University"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warsaw, Poland"</span>,</span>
<span id="cb8-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Physics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1893"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span>,</span>
<span id="cb8-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Mathematics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1894"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span></span>
<span id="cb8-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detailed_entries</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">what =</span> Degree, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">when =</span> Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with =</span> Institution, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where =</span> Where)</span></code></pre></div></div>
</div>
<p>with this</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb9-1">CV<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(section <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'education'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detailed_entries</span>(</span>
<span id="cb9-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">what =</span> institution,</span>
<span id="cb9-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">when =</span> glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{`start`} - {`end`}"</span>),</span>
<span id="cb9-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with =</span> title,</span>
<span id="cb9-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where =</span> loc,</span>
<span id="cb9-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> description_bullets</span>
<span id="cb9-9">  )</span></code></pre></div></div>
</div>
<p>To print your skills</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb10-1">CV <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print_skill</span>()</span></code></pre></div></div>
</div>
<p>To print your posts</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1">CV <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&lt;&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print_post</span>()</span></code></pre></div></div>
</div>
<p>All files are hosted <a href="https://github.com/DarwinCV/automated-CV">here</a>.</p>
<p>I want to thank <strong>Nick Strayer</strong> and <strong>Mitchell O’Hara-Wild</strong> for the wonderful work done on the vitae and datadrivencv package.</p>


</section>

 ]]></description>
  <guid>https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/</guid>
  <pubDate>Wed, 02 Mar 2022 00:00:00 GMT</pubDate>
  <media:content url="https://darwincubi.rbind.io/post/2022-03-02-how-to-create-a-cv-with-rmarkdown-awesome-cv-and-google-sheets/pic1.png" medium="image" type="image/png" height="120" width="144"/>
</item>
<item>
  <title>Como crear un CV con Rmarkdown, Awesome CV y Google Sheet</title>
  <link>https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/</link>
  <description><![CDATA[ 
Skip to main content
<script>
  document.body.prepend(document.querySelector(".skip-link"));
</script>




<section id="cv-en-r" class="level3">
<h3 class="anchored" data-anchor-id="cv-en-r">CV en R</h3>
<p>Al ingresar al mundo laboral o en la búsqueda de nuevas oportunidades de empleo todos hemos estado en la tarea de crear o actualizar nuestro curriculum y casi siempre la principal herramienta es Word seguido de Canva o Adobe ilustrator (para los mas avanzados). Las dos ultimas opciones si bien ofrecen mucha personalización en cuanto diseño no permiten tanta flexibilidad al momento de actualizar información o que se adapten facilmente a un flujo de trabajo. Por otro lado Word tienen plantillas con diseños algo sosos y la lucha constante con las alineaciones, sangrados y estilos al momento de ingresar nueva información.</p>
<p>Hace un par de años me enfrente a este problema y tuve la suerte de encontrar la solución en el paquete vitae desarrollado por <a href="https://github.com/mitchelloharawild/vitae"><strong>Mitchell O’Hara-Wild</strong></a>. Este paquete permite crear un cv con 6 tipos de formato:</p>
<ol type="1">
<li>Awesome-CV format</li>
<li>Hydman</li>
<li>ModernCV</li>
<li>Twenty seconds</li>
<li>latexcv</li>
<li>markdown-cv</li>
</ol>
<p><a href="https://github.com/mitchelloharawild/vitae#examples-of-using-vitae">Aquí</a> puede ver los ejemplos de los diferentes formatos junto con su código fuente. En los personal me agrada la plantilla Awesome-CV y de hecho todo este tutorial se desarrollada enfocada a este estilo de cv.</p>
<p>Primero deberá crear un proyecto en Rstudio pues aprovecharemos el control de versiones git, en este <a href="https://www.geo.uzh.ch/microsite/reproducible_research/post/rr-rstudio-git/#:~:text=In%20RStudio%20Select%20File%20%3E%20New,repository%20to%20your%20project%20folder">enlace</a> podrá encontrar el paso a paso de como crear un proyecto con control de versiones git.</p>
<p>El primer paso será instalar el paquete vitae</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vitae"</span>)</span></code></pre></div></div>
<p>y luego crear una plantilla de awesome cv con markdown</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/pic1.png" loading="lazy" decoding="async" alt="Menú de RStudio para crear un documento R Markdown" width="792" height="658"> <img src="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/pic2.png" loading="lazy" decoding="async" alt="Diálogo de plantillas R Markdown con el formato Awesome CV seleccionado" width="1188" height="1036"> Esto creara la siguiente plantilla</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/pic3.png" loading="lazy" decoding="async" alt="Editor de RStudio con parámetros YAML y entradas de ejemplo para Awesome CV" width="1382" height="834"> Para compilar deberá dar click en ‘Knit’ y tendrá el siguiente pdf</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/pic4.png" loading="lazy" decoding="async" alt="Ejemplo de Awesome CV renderizado para Marie Curie" width="1078" height="830"> En los parámetros YAML puede especificar datos como nombre, posición, dirección, email, etc. <a href="https://cran.r-project.org/web/packages/vitae/vignettes/vitae.html">Aquí</a> podrá encontrar más detalle acerca de cada parámetro disponible.</p>
<p>Las datos para el cv se ingresan en un tribble y se transforman a formato awesome con la función <code>detailed_entries()</code> que tiene los parametros:</p>
<ul>
<li>data: tribble, tibble o dataframe con los datos</li>
<li>what: nombre de la actividad o titulo</li>
<li>when: fecha de la actividad o titulo</li>
<li>with: empresa o institución</li>
<li>where: lugar de la actividad o titulo</li>
<li>why : para datos adicionales (estos pueden ser una lista de valores)</li>
</ul>
<p>También existe función <code>brief_entries(data, what, when, with, .protect = TRUE)</code> que es similar pero con menos argumentos. Para mas informacion acerca de estas funciones puede escribir en la consola <code>?detailed_entries</code> o <code>?brief_entries</code></p>
<p>El siguiente código</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb2-2">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Degree, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Year, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Institution, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Where,</span>
<span id="cb2-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Informal studies"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1889-91"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flying University"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warsaw, Poland"</span>,</span>
<span id="cb2-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Physics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1893"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span>,</span>
<span id="cb2-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Mathematics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1894"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span></span>
<span id="cb2-6">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detailed_entries</span>(Degree, Year, Institution, Where)</span></code></pre></div></div>
</div>
<p>al compilar a pdf creará</p>
<p><img src="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/pic5.png" loading="lazy" decoding="async" alt="Entradas de educación generadas desde datos estructurados en R" width="993" height="191"> Hasta este punto habra credo un cv funcional y no tendrá que preocuparse del diseño, sangrado o alineación del texto. Pero aun sigue siendo engorroso tener los datos y el código en el mismo lugar. Para resolver este problem tome como base el flujo de trabajo del paquete <a href="http://nickstrayer.me/datadrivencv/">datadrivencv</a> creado por <a href="https://github.com/nstrayer">Nick Strayer</a>.</p>
</section>
<section id="guardar-sus-datos-en-google-sheets" class="level3">
<h3 class="anchored" data-anchor-id="guardar-sus-datos-en-google-sheets">Guardar sus datos en Google sheets</h3>
<p>Utilizaremos el paquete <code>googlesheets4</code> para descargar los datos de nuestro cv desde una hoja de calculo de Google. Sugiero copiar mi <a href="https://docs.google.com/spreadsheets/d/1AN85IIvbcMnGbcOCX3jurB4fMOp_niAUbDBU_zfjFEw/edit?usp=sharing">hoja</a> y reemplazar sus datos. <img src="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/pic6.png" loading="lazy" decoding="async" alt="Libro de Google Sheets con entradas estructuradas para el CV" width="1317" height="805"> El documento tiene las siguientes:</p>
<ol type="1">
<li>entries: información acerca de educación, experiencia laboral, certificaciones, etc.</li>
<li>lenguaje_skills: herramientas o habilidades que maneja.</li>
<li>post_info: informacion acerca de post.</li>
<li>text_block: informacion adicional como su descripción profesional o intereses.</li>
<li>contact_info: información de contacto (email, teléfono, etc)</li>
</ol>
</section>
<section id="crear-funciones-personalizadas" class="level3">
<h3 class="anchored" data-anchor-id="crear-funciones-personalizadas">Crear funciones personalizadas</h3>
<p>La siguiente función permite crear un objeto con toda la información de la hoja de calculo,</p>
<ol type="1">
<li>data_location: es el link de la hoja de calculo de google sheet</li>
<li>pdf_mode: si es TRUE se eliminan los link de los textos.</li>
<li>sheet_is_publicly_readable: TRUE si el link de la hoja de calculo es público</li>
</ol>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb3-1">create_CV_object <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data_location,</span>
<span id="cb3-2">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_mode =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb3-3">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_is_publicly_readable =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) {</span>
<span id="cb3-4">  </span>
<span id="cb3-5">  cv <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb3-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_mode =</span> pdf_mode,</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>()</span>
<span id="cb3-8">  )</span>
<span id="cb3-9">  </span>
<span id="cb3-10">  is_google_sheets_location <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"docs</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.google</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.com"</span>)</span>
<span id="cb3-11">  </span>
<span id="cb3-12">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(is_google_sheets_location){</span>
<span id="cb3-13">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(sheet_is_publicly_readable){</span>
<span id="cb3-14">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This tells google sheets to not try and authenticate. Note that this will only</span></span>
<span id="cb3-15">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># work if your sheet has sharing set to "anyone with link can view"</span></span>
<span id="cb3-16">      googlesheets4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gs4_deauth</span>()</span>
<span id="cb3-17">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb3-18">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># My info is in a public sheet so there's no need to do authentication but if you want</span></span>
<span id="cb3-19">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to use a private sheet, then this is the way you need to do it.</span></span>
<span id="cb3-20">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># designate project-specific cache so we can render Rmd without problems</span></span>
<span id="cb3-21">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gargle_oauth_cache =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".secrets"</span>)</span>
<span id="cb3-22">    }</span>
<span id="cb3-23">    </span>
<span id="cb3-24">    read_gsheet <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(sheet_id){</span>
<span id="cb3-25">      googlesheets4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_sheet</span>(data_location, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet =</span> sheet_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_types =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>)</span>
<span id="cb3-26">    }</span>
<span id="cb3-27">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"entries"</span>)</span>
<span id="cb3-28">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>skills        <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"language_skills"</span>)</span>
<span id="cb3-29">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text_blocks   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text_blocks"</span>)</span>
<span id="cb3-30">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>contact_info  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contact_info"</span>)</span>
<span id="cb3-31">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post_info  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_gsheet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sheet_id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post_info"</span>)</span>
<span id="cb3-32">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb3-33">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Want to go old-school with csvs?</span></span>
<span id="cb3-34">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"entries.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-35">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>skills       <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"language_skills.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-36">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text_blocks  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text_blocks.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-37">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>contact_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"contact_info.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-38">    cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> readr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(data_location, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post_info.csv"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-39">  }</span>
<span id="cb3-40">  </span>
<span id="cb3-41">  </span>
<span id="cb3-42">  extract_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(dates){</span>
<span id="cb3-43">    date_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(dates, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(20|19)[0-9]{2}"</span>)</span>
<span id="cb3-44">    date_year[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(date_year)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year</span>(lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ymd</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.Date</span>())) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb3-45">    </span>
<span id="cb3-46">    date_year</span>
<span id="cb3-47">  }</span>
<span id="cb3-48">  </span>
<span id="cb3-49">  parse_dates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(dates){</span>
<span id="cb3-50">    </span>
<span id="cb3-51">    date_month <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(dates, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">w+|</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)(?=(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">s|</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/|-)(20|19)[0-9]{2})"</span>)</span>
<span id="cb3-52">    date_month[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(date_month)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span></span>
<span id="cb3-53">    </span>
<span id="cb3-54">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>, date_month, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_year</span>(dates), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-55">      lubridate<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dmy</span>()</span>
<span id="cb3-56">  }</span>
<span id="cb3-57">  </span>
<span id="cb3-58">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Clean up entries dataframe to format we need it for printing</span></span>
<span id="cb3-59">  cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&lt;&gt;%</span></span>
<span id="cb3-60">    tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unite</span>(</span>
<span id="cb3-61">      tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">starts_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'description'</span>),</span>
<span id="cb3-62">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description_bullets"</span>,</span>
<span id="cb3-63">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- "</span>,</span>
<span id="cb3-64">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb3-65">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-66">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">description_bullets =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(description_bullets , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- "</span>)) ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-67">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb3-68">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># description_bullets = ifelse(description_bullets != "", paste0("- ", description_bullets), ""),</span></span>
<span id="cb3-69">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NULL"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, start),</span>
<span id="cb3-70">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NULL"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, end),</span>
<span id="cb3-71">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start_year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_year</span>(start),</span>
<span id="cb3-72">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_year</span>(end),</span>
<span id="cb3-73">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">no_start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(start),</span>
<span id="cb3-74">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">has_start =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>no_start,</span>
<span id="cb3-75">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">no_end =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(end),</span>
<span id="cb3-76">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">has_end =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>no_end,</span>
<span id="cb3-77">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">timeline =</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb3-78">        no_start  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> no_end  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"N/A"</span>,</span>
<span id="cb3-79">        no_start  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> has_end <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(end),</span>
<span id="cb3-80">        has_start <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> no_end  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Current"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, start),</span>
<span id="cb3-81">        <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>                <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(end, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, start)</span>
<span id="cb3-82">      )</span>
<span id="cb3-83">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-84">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parse_dates</span>(end))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-85">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate_all</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(.), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'N/A'</span>, .))</span>
<span id="cb3-86">  </span>
<span id="cb3-87">  cv</span>
<span id="cb3-88">}</span></code></pre></div></div>
</div>
<p>Esta función elimina los links de un texto</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1">sanitize_links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv, text){</span>
<span id="cb4-2">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pdf_mode){</span>
<span id="cb4-3">    link_titles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract_all</span>(text, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[).+?(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">])'</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb4-4">    link_destinations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract_all</span>(text, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">().+?(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">))'</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb4-5">    </span>
<span id="cb4-6">    n_links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>links)</span>
<span id="cb4-7">    n_new_links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(link_titles)</span>
<span id="cb4-8">    </span>
<span id="cb4-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(n_new_links <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>){</span>
<span id="cb4-10">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add links to links array</span></span>
<span id="cb4-11">      cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>links <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>links, link_destinations)</span>
<span id="cb4-12">      </span>
<span id="cb4-13">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Build map of link destination to superscript</span></span>
<span id="cb4-14">      link_superscript_mappings <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_names</span>(</span>
<span id="cb4-15">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;sup&gt;"</span>, (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_new_links) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n_links, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;/sup&gt;"</span>),</span>
<span id="cb4-16">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"("</span>, link_destinations, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">")"</span>)</span>
<span id="cb4-17">      )</span>
<span id="cb4-18">      </span>
<span id="cb4-19">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Replace the link destination and remove square brackets for title</span></span>
<span id="cb4-20">      text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> text <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-21">        stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fixed</span>(link_superscript_mappings)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-22">        stringr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace_all</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[(.+?)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">]'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">1"</span>)</span>
<span id="cb4-23">    }</span>
<span id="cb4-24">  }</span>
<span id="cb4-25">  </span>
<span id="cb4-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> cv, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> text)</span>
<span id="cb4-27">}</span></code></pre></div></div>
</div>
<p>También se necesita funciones para imprimir los datos descargados</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print text block</span></span>
<span id="cb5-2">print_text_block <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv, label){</span>
<span id="cb5-3">  text_block <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text_blocks, loc <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> label) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-4">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(text)</span>
<span id="cb5-5">  </span>
<span id="cb5-6">  strip_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sanitize_links</span>(cv, text_block)</span>
<span id="cb5-7">  </span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(strip_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text)</span>
<span id="cb5-9">  </span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(strip_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cv)</span>
<span id="cb5-11">}</span>
<span id="cb5-12"></span>
<span id="cb5-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print table of skills</span></span>
<span id="cb5-14">print_skill <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv){</span>
<span id="cb5-15">  </span>
<span id="cb5-16">  glue_template <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-17"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">cvskill{&lt;&lt;group&gt;&gt;}{&lt;&lt;skills&gt;&gt;}"</span></span>
<span id="cb5-18">  </span>
<span id="cb5-19">  skills_formatted <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>skills <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(details)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>details<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{skill}"</span>), glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{skill} ({details})"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skills =</span> glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_collapse</span>(skill, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>)) </span>
<span id="cb5-23">  </span>
<span id="cb5-24">  cv_skill <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> skills_formatted <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-25">    glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_data</span>(glue_template, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.open =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;&lt;"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.close =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;&gt;"</span> ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)</span>
<span id="cb5-27">  </span>
<span id="cb5-28">  cv_skill_env <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">begin{cvskills}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>, cv_skill, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">end{cvskills}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span> , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)</span>
<span id="cb5-29">  </span>
<span id="cb5-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(cv_skill_env)</span>
<span id="cb5-31">  </span>
<span id="cb5-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(cv)</span>
<span id="cb5-33">}</span>
<span id="cb5-34"></span>
<span id="cb5-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print table of posts</span></span>
<span id="cb5-36">print_post<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(cv, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">glue_template =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"default"</span>){</span>
<span id="cb5-37">  </span>
<span id="cb5-38">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(glue_template <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"default"</span>){</span>
<span id="cb5-39">    glue_template <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">- [{name}]({link})</span></span>
<span id="cb5-41"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-42">  }  </span>
<span id="cb5-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_data</span>(cv<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post_info , glue_template))</span>
<span id="cb5-44">  </span>
<span id="cb5-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(cv)</span>
<span id="cb5-46">}</span></code></pre></div></div>
</div>
<p>Bien, ahora reemplacemos</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>opts_chunk<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">echo =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warning =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(vitae)</span></code></pre></div></div>
</div>
<p>por esto, para poder usar las funciones anteriores</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb7-1">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>opts_chunk<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">echo =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warning =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(vitae)</span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb7-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(magrittr)</span>
<span id="cb7-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Utils/data_download_funs.R"</span>)</span>
<span id="cb7-6"></span>
<span id="cb7-7">CV <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create_CV_object</span>(</span>
<span id="cb7-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_location =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://docs.google.com/spreadsheets/d/19YWFjpiCqTbrwrU1hpxDNubZKoNi-o0DvOQbcHqsc7c/edit?usp=sharing"</span>,  </span>
<span id="cb7-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_mode =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb7-10">)</span></code></pre></div></div>
</div>
<p>Para la sección de Educación podemos reemplazar</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tibble)</span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb8-3">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Degree, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Year, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Institution, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Where,</span>
<span id="cb8-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Informal studies"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1889-91"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flying University"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warsaw, Poland"</span>,</span>
<span id="cb8-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Physics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1893"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span>,</span>
<span id="cb8-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Master of Mathematics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1894"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sorbonne Université"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Paris, France"</span></span>
<span id="cb8-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detailed_entries</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">what =</span> Degree, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">when =</span> Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with =</span> Institution, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where =</span> Where)</span></code></pre></div></div>
</div>
<p>por</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb9-1">CV<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(section <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'education'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detailed_entries</span>(</span>
<span id="cb9-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">what =</span> institution,</span>
<span id="cb9-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">when =</span> glue<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{`start`} - {`end`}"</span>),</span>
<span id="cb9-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with =</span> title,</span>
<span id="cb9-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">where =</span> loc,</span>
<span id="cb9-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">why =</span> description_bullets</span>
<span id="cb9-9">  )</span></code></pre></div></div>
</div>
<p>Para imprimir sus habilidades</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb10-1">CV <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print_skill</span>()</span></code></pre></div></div>
</div>
<p>Para imprimir sus posts</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1">CV <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&lt;&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print_post</span>()</span></code></pre></div></div>
</div>
<p>Todos los archivos se encuentran alojado <a href="https://github.com/DarwinCV/automated-CV">aquí</a>.</p>
<p>Quiero agredecer a <strong>Nick Strayer</strong> y <strong>Mitchell O’Hara-Wild</strong> por el maravilloso trabajo realizado en el paquete vitae y datadrivencv.</p>


</section>

 ]]></description>
  <guid>https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/</guid>
  <pubDate>Wed, 02 Mar 2022 00:00:00 GMT</pubDate>
  <media:content url="https://darwincubi.rbind.io/post/2022-03-03-como-crear-un-cv-con-rmarkdown-awesome-cv-y-google-sheet/featured.jpeg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Introducción al Seguro</title>
  <link>https://darwincubi.rbind.io/post/2021-07-04-introduccion-al-seguro/</link>
  <description><![CDATA[ 
Skip to main content
<script>
  document.body.prepend(document.querySelector(".skip-link"));
</script>




<p>Para muchas personas la palabra “póliza” no resulta un termino extraño y las primeras ideas en su cabeza es protección, vehículo o seguro, esto debido a que comprar una póliza de seguro es una actividad muy frecuente y común hoy en día. Sin embargo las palabras “actuario” o “ciencia actuarial” resultan totalmente desconocidas para el común de las personas y para un segmento de personas dentro del mismo mercado de seguros, irónico verdad.</p>
<p>No se desanime si tampoco conoce estos términos pues hace tres años también lo eran para mi cuando ingrese a una aseguradora ecuatoriana. En este articulo daré una introducción al seguro basado en la experiencia y auto formación a lo largo de mi estancia en una aseguradora. Entonces empecemos con un poco de historia.</p>
<section id="historia" class="level2">
<h2 class="anchored" data-anchor-id="historia">Historia</h2>
<p><img src="https://darwincubi.rbind.io/post/2021-07-04-introduccion-al-seguro/history.jpeg" loading="lazy" decoding="async" alt="Biblioteca histórica con libros antiguos y bustos de pensadores" width="2400" height="1600"></p>
<p>Los seguros empezaron su desarrollo en el siglo XIV como protección a los comerciantes marítimos en contra de la piratería, deterioro en el transporte o riesgos propios del medio de transporte como tormentas o hundimientos. Uno de los primeros contratos de seguro que conocemos aparece el 15 de marzo de 1350, en el cual el genovés, Leonardo Cattaneo, promete asumir la perdida del cargamento avaluado en 300 florines ya sea por un acto de dios o por mano del hombre durante el trayecto desde la isla de Sicilia hasta Tunez; en el contrato también se estipula un pago de 54 florines que corresponde al 18% del valor del cargamento (18% = 54/300) por dicha promesa. El pago por estos contratos de seguros era muy altos en comparación a los que se pagan hoy en día pues en la época medieval estos cubrían riesgos de guerra, de la naturaleza y que los accidentes marítimos eran muy frecuentes. El pago variaba de acuerdo a la distancia recorrida, la estación del año, si había guerra o paz, si habían ocurrido actos de piratería en la ruta, tipo de embarcación o simplemente de año a año. Por ejemplo el pago por transportar mercadería entre Londres y Pisa variaba entre el 12% y el 15% del valor asegurado es decir del valor de la mercancía y en ciertas ocasiones un porcentaje mayor por existir actos de piratería. Con el desarrollo de los contratos de seguro también vinieron los problemas como por ejemplo que las personas con poca experiencia en el negocio de seguros no tenían la capacidad financiera para responder en caso de perdida de mercancía de gran valor. También aparecieron personas que usaron los contratos de seguros no como una protección sino como una forma de apostar sobre los bienes de otros. Para comienzos del siglo XV el seguro marítimo estaba bien establecido pues se habían definido: reglas con las cuales evitar los problemas antes mencionados una estructura para el contrato de seguro o también llamado póliza y que cambio muy poco en los siglos siguientes.</p>
<p>La utilización de formatos predeterminados para pólizas era tan común en el siglo XVI que únicamente se tenia que especificar el nombre del capitán, nombre del barco, valor de la mercancía, pago por el seguro y detalles específicos que variaban de contrato en contrato. Se estandarizo la interpretación legal de las pólizas y establecieron cosas como que el asegurador que hubiese pagado una indemnización adquiría los derechos de propiedad sobre lo que se pueda recuperar de los bienes asegurados o también llamados salvamentos y que en caso que el asegurado no renunciara al derecho de propiedad la indemnización no era pagadera. También que el asegurador no era responsable si la embarcación se hundía antes de partir o si había razones para creer que el asegurado ocultaba información acerca del riesgo. No se podía indemnizar por un valor superior al valor real del bien asegurado y no se podía acceder a una póliza si el asegurado no era el dueño del bien o que podía verse afectado de manera indirecta por la perdida del bien.</p>
</section>
<section id="que-es-un-seguro" class="level2">
<h2 class="anchored" data-anchor-id="que-es-un-seguro">Que es un seguro</h2>
<p>El seguro surge como respuesta a la incertidumbre que sienten los individuos frente a situaciones adversas que puedan provocar perdidas tanto materiales como personales.</p>
<blockquote class="blockquote">
<p><strong>La base de esta actividad radica en la existencia de un equilibrio entre la prestación (indemnización) que hará la compañía de seguros y la contraprestación (prima) que ella recibe del asegurado</strong></p>
</blockquote>
<p>La actividad aseguradora, como cualquier otra tiene su propia forma de expresarse. Algunos términos frecuentes:</p>
<ul>
<li><strong>Seguro</strong>: entendido como contrato, es el convenio entre dos partes, entre asegurador y asegurado mediante la cual la primera se compromete a cubrir económicamente la perdida o daño que el asegurado pueda sufrir.</li>
<li><strong>Riesgo</strong>: es la posibilidad de perdida o daño.</li>
<li><strong>Siniestro</strong>: es la realización del riesgo.</li>
<li><strong>Prima</strong>: es el precio del seguro.</li>
</ul>
<p>El seguro tiene 2 características fundamentales:</p>
<ol type="1">
<li>Transferencia del riesgo de un individuo ( una persona, una familia, una empresa) a un grupo de individuos (familias, empresas)</li>
<li>Compartir las perdidas en alguna manera equitativa sobre todos los miembros del grupo, a esta idea comúnmente se le conoce como “riesgo compartido”</li>
</ol>
<p>Se debe hacer una distinción entre “riesgo compartido” y “ diversificación de riesgo”. El primero es el fundamento del seguro mientras que el segundo se ocupa de optimizar el riesgo en una cartera de inversiones es decir reducir el riesgo total.</p>
<p>Por otro lado, desde el punto de vista del asegurado, se puede definir el seguro como un herramienta económica mediante el cual el asegurado cambia un costo pequeño y conocido (llamado prima) por un costo desconocido y potencialmente grande (perdida financiera). Es decir cambiamos incertidumbre por la certeza mediante un contrato de seguro.</p>
<p>También desde un punto de vista social, el seguro se pude definir como una herramienta económica mediante la cual se puede reducir o eliminar un riesgo a través de combinar un numero suficiente de expuestos o asegurados homogéneos (que tengan características similares) en un grupo de tal manera que las perdidas puedan ser predecibles como un todo.</p>
</section>
<section id="porque-es-necesario-el-seguro" class="level2">
<h2 class="anchored" data-anchor-id="porque-es-necesario-el-seguro">Porque es necesario el seguro</h2>
<ol type="1">
<li>En general las personas y la sociedad tienen la necesidad de protección frente a eventos imprevisibles que podrían causar serias perdidas financieras o físicas.</li>
<li>Un seguro se encarga de reponer las perdidas de un evento aleatorio desfavorable.</li>
</ol>
<p>El proceso fundamental tras el seguro, es que la aseguradora construye una “comunidad” o portafolio de asegurados en donde todos contribuyen con el pago de cierto monto, conocido de antemano, y las perdidas económicas derivadas de eventos desfavorables son financiadas por medio de esta comunidad.</p>
<p>Los miembros de esta comunidad deben enfrentar riesgos similares y por ende todos se benefician al diversificar el mismo riesgo.</p>
<blockquote class="blockquote">
<p><strong>La contribución de muchos para cubrir la desgracia de pocos</strong></p>
</blockquote>
<p>Los contratos de seguro tienen:</p>
<ul>
<li>Un periodo de cobertura, para seguros de no-vida o también conocido como generales la cobertura habitualmente dura 1 año ( por ejemplo seguro de vehículo, seguro contra incendio ) mientas que en seguros de vida las coberturas pueden durar muchos años por ejemplo 20 años o hasta la edad de retiro ( seguro de vida, seguro de muerte) .</li>
<li>Todos aquellos eventos que ocurren durante el periodo de vigencia causando una perdida financiera y que están cubiertos por el contrato son indemnizados.</li>
<li>Los pagos causados por eventos cubiertos son llamados “reclamos de seguro”.</li>
<li>El pago que realiza el asegurado se conoce como “prima de seguro” y típicamente se realiza al inicio de la cobertura.</li>
</ul>
<p>Una característica singular del seguro es que su ciclo <strong>de producción es inverso.</strong> Para entender mejor este concepto veamos como es el ciclo de producción para una fabrica de ropa. Primero la fabrica adquiere la materia prima, por lo cual de antemano conoce el costo de la misma. Luego necesitará la mano de obra para diseñar y crear las prendas, estos costos también los conocerá. Para colocar el precio de una prenda para el cliente tendrá que sumar el costo de la materia prima, el costo de la mano de obra y el valor que el fabricante desee como ganancia. En los seguros no se puede conocer de antemano cual será el costo o pago por un reclamo de seguro, también dependiendo del evento en ocasiones es necesario contratar abogados u otros servicios cuyo costo también es desconocido. Es por esto que decimos que los seguros tienen un ciclo de producción inverso y esta es la razón por la cual los modelos de perdida son esenciales.</p>
<blockquote class="blockquote">
<p><strong>No se puede conocer el costo de un seguro antes de su periodo de cobertura</strong></p>
</blockquote>
<blockquote class="blockquote">
<p><strong>La ley de los grandes números dice que al expandir el número de riesgo en un grupo, la pérdida promedio en el grupo eventualmente se vuelve cierta.</strong></p>
</blockquote>
<p>Formulando en forma matemática la cita anterior, para una compañía de seguros que agrupa riesgos similares</p>
<p>Sean <img src="https://latex.codecogs.com/png.latex?Y_1,%20...,%20Y_n"> reclamaciones individuales de <img src="https://latex.codecogs.com/png.latex?n%20%5Cin%20N"> asegurados , tal que todos las <img src="https://latex.codecogs.com/png.latex?Y_i"> son variables aleatorias <strong>independientes e idénticamente distribuidas</strong> cuya esperanza es <img src="https://latex.codecogs.com/png.latex?%5Cmu">. Entonces para cualquier <img src="https://latex.codecogs.com/png.latex?%5Cepsilon%3E0"></p>
<p><img src="https://latex.codecogs.com/png.latex?P%5C%7B%7C%5Cfrac%7BY_1%20+%20....%20+%20Y_n%7D%7Bn%7D%20-%20%5Cmu%7C%3E%20%5Cepsilon%20%5C%7D%20%5Cto%200%20%5Ctext%7B%20cuando%20%7D%20n%20%5Cto%20+%5Cinfty"></p>
<p>Lo que nos dice la ley débil de los grandes numeros es que la probabilidad que la perdida promedio en un grupo de riesgos se desvíe de la perdida esperada en mas de una cantidad especificada eventualmente será 0 mientras el grupo de riesgos crece.</p>
<p>Si bien la LGN nos dice que la desviación de la perdida promedio disminuye en un grupo en crecimiento, no podemos:</p>
<ol type="1">
<li>Decir respecto a la perdida agregada de perdidas del grupo de riesgos, que en la practica es el valor que mas importa a una aseguradora.</li>
<li>Si los riesgos tienen un componente en común esta ley no es aplicable.</li>
<li>En la realidad expandir <img src="https://latex.codecogs.com/png.latex?n"> hasta el infinito.</li>
</ol>
<p>Para un portafolio o pool de asegurados en expansión el creciente conjunto de riesgos se reparte entre un número cada vez mayor de propietarios. Es la pérdida promedio del pool, la que se atribuye a un propietario individual, cuya variabilidad como hemos visto antes por la LGN se reduce mucho con la agrupación de riesgos. Esto es el porque la LGN es el núcleo central del seguro.</p>


</section>

 ]]></description>
  <guid>https://darwincubi.rbind.io/post/2021-07-04-introduccion-al-seguro/</guid>
  <pubDate>Sun, 04 Jul 2021 00:00:00 GMT</pubDate>
  <media:content url="https://darwincubi.rbind.io/post/2021-07-04-introduccion-al-seguro/featured.png" medium="image" type="image/png" height="75" width="144"/>
</item>
<item>
  <title>Juego de la Vida de Conway</title>
  <link>https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/</link>
  <description><![CDATA[ 
Skip to main content
<script>
  document.body.prepend(document.querySelector(".skip-link"));
</script>




<p>La pandemia del covid 19 que inició en diciembre del 2019 ha sido una pandemia que ha puesto en hacke a toda la humanidad. Tomando sorpresivamente a casi todas las naciones del mundo y solamente a unas pocas medianamente preparadas. Con las pérdidas económicas y cese de actividades lo más valioso que se ha llevado la pandemia ha sido las vidas humanas, pues este virus no conoce de política, religión o género. Entre las muchas vidas que se perdieron esta <a href="https://es.wikipedia.org/wiki/John_Horton_Conway">Jhon Horton Conway</a> quien fue un prolífico matemático británico especialista en varias áreas de la matemática tales como la teoría de juegos, teoría de nudos, teoría de números. Entre sus aportes matemáticos, destaca uno en el campo de los autómatas celulares bautizado como el “Juego de la Vida” o “Vida”. Si bien es un juego tiene la particularidad que es de 0 jugadores, se rige por tres reglas muy sencillas y su evolución depende del estado inicial del juego. Las reglas que rigen el juego son:</p>
<ol type="1">
<li>Cualquier célula viva con menos de dos vecinos o más de tres vecinos vivos muere, como por subpoblación o sobrepoblación correspondientemente.</li>
</ol>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/regla1.jpeg" loading="lazy" decoding="async" alt="Diagrama de la regla uno del Juego de la Vida sobre subpoblación y sobrepoblación" width="361" height="94"></p>
<ol start="2" type="1">
<li>Cualquier célula muerta con exactamente tres vecinos vivos se convierte en una célula viva, como por reproducción.</li>
</ol>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/regla2.jpeg" loading="lazy" decoding="async" alt="Diagrama de la regla dos del Juego de la Vida sobre reproducción" width="362" height="86"></p>
<ol start="3" type="1">
<li>Cualquier célula viva con dos o tres vecinos vivos vive hasta la próxima generación.</li>
</ol>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/regla3.jpeg" loading="lazy" decoding="async" alt="Diagrama de la regla tres del Juego de la Vida sobre supervivencia" width="360" height="83"></p>
<p>El sistema es espacial y temporalmente discreto. Su evolución es en pasos discretos es decir el sistema tiene un estado para un tiempo <code>t=0</code> (que es el que nosotros definimos), luego el estado del sistema cambia en un tiempo <code>t=1</code> pero que depende del estado en <code>t=0</code>, el estado vuelve a cambiar en un tiempo <code>t=2</code> que depende del estado en <code>t=1</code> y así sucesivamente hasta un tiempo <code>t=n</code>&nbsp;, siendo <code>n</code> un número entero.</p>
<p>A primera vista no parece la gran cosa pero este sistema sencillo puede evolucionar en un sistema complejo con un comportamiento similar al de la evolución de la vida misma. Además en sí mismo este autómata celular es una máquina de touring, es decir que en él se puede implementar cualquier algoritmo que se derive de un problema matemático.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/reloj.gif" loading="lazy" decoding="async" alt="Animación de un reloj construido con patrones del Juego de la Vida" width="578" height="399"></p>
<p>Por ejemplo se pueden programar relojes o salidas sencillas que muestren texto.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/text.gif" loading="lazy" decoding="async" alt="Animación de células que forman texto en el Juego de la Vida" width="374" height="95"></p>
<p>o incluso uno que simule el tejido del universo.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/tejido.gif" loading="lazy" decoding="async" alt="Animación de un patrón celular complejo que se expande" width="256" height="256"></p>
<p>Si estas interesado en observar más patrones <a href="https://conwaylife.appspot.com/library">aqui</a> puedes encontrar una larga biblioteca.</p>
<p>El observar como se crean sistemas complejos ha abierto investigaciones enfocadas en aplicaciones filosóficas: estas van desde la filosofía de la computación y el procesamiento de la información, hasta los relatos de reducción y surgimiento en la metafísica y la cognición, los debates sobre los fundamentos de la física, el libre albedrío, la naturaleza de la computación y la plausibilidad física de un mundo digital (es decir si es posible que vivamos en la matriz) 😝.</p>
<p>En fin, la teoria de automatas celular y sus aplicaciones es prometedora y demasiado basta así que sus detalles los obviamos. Entendida la belleza de este juego es hora de pasar a la implementación.</p>
<p>La idea que seguiremos es:</p>
<ol type="1">
<li>Crear una matriz con <code>nx</code> número de filas y <code>ny</code> número de columnas.</li>
<li>Los valores de la matriz serán 1 o 0 que significa vivo o muerto respectivamente.</li>
<li>Creamos una copia de la matriz.</li>
<li>Usando bucles recorremos la matriz y para cada celda calculamos el número de vecinos y aplicamos las reglas antes definidas.</li>
<li>El resultado de aplicar las reglas lo guardamos en la copia de la matriz del paso 3.</li>
<li>Los pasos 3, 4 y 5 se repiten el número de veces que deseamos usando un bucle (while o for).</li>
</ol>
<p><strong>Manos a la obra !!!!</strong></p>
<p><img src="https://tenor.com/view/yes-zoom-nod-meme-challenge-accepted-gif-14984274.gif" class="img-fluid" loading="lazy" decoding="async" alt="Animación de reacción: desafío aceptado"></p>
<p>La implementación del autómata es en lenguaje Python, empezamos por las librerías</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pygame</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>  time</span></code></pre></div></div>
<p>La librería <strong>numpy</strong> nos servirá para crear una matriz de ceros y unos aleatorios, <strong>matploblib</strong> para graficar la evolución de la matriz en cada paso y <strong>pygame</strong> que nos servirá para implementar la lógica con un interfaz de usuario usando el teclado para pausar y salir del juego y el ratón para borrar o agregar el estado de una celda de la matriz. Ahora definamos el número de filas y columnas, en este caso son iguales formando un cuadrado.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb2-1">nx_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filas </span></span>
<span id="cb2-2">ny_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#columnas</span></span>
<span id="cb2-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Matriz de estados</span></span>
<span id="cb2-4">state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.randint(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, (nx_cell, ny_cell)) </span>
<span id="cb2-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(state_game) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#impresion en consola</span></span>
<span id="cb2-6">plt.matshow(state_game) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#grafico de la matriz de estados</span></span>
<span id="cb2-7">plt.show()</span></code></pre></div></div>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/matriz.png" loading="lazy" decoding="async" alt="Matriz de treinta por treinta con celdas vivas en amarillo y muertas en morado" width="480" height="480"></p>
<p>Si todo a salido bien debería ver una grafico similar al de arriba, las celdas amarillas están vivas y las moradas están muertas.</p>
<p>Dentro de un <code>while</code> con condicion <code>True</code> (para que se repita indefinidamente) usando dos for anidados para acceder a cada celda calculamos el número de vecinos que rodean a una celda. Como cada celda toma el valor 0 o 1 entonces la suma de vecinos puede ser 0 como mínimo y 8 como máximo. Las coordenadas de los vecinos se presentan a continuación.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/vecinos.gif" loading="lazy" decoding="async" alt="Animación que identifica los ocho vecinos de una celda" width="800" height="600"></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>:</span>
<span id="cb3-2"></span>
<span id="cb3-3">    new_state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.copy(state_game)</span>
<span id="cb3-4"></span>
<span id="cb3-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, nx_cell):</span>
<span id="cb3-6">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> y <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, ny_cell):</span>
<span id="cb3-7"></span>
<span id="cb3-8">                n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> state_game[(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell ] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-9">                            state_game[x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-10">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-11">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-12">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-13">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-14">                            state_game[x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-15">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] </span>
<span id="cb3-16"></span>
<span id="cb3-17">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">''' Una célula muerta con exactamente 3 células vecinas vivas "nace" (es decir, al turno siguiente estará viva</span></span>
<span id="cb3-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">                    Si una célula viva tiene menos de 2 o mas de 3 células vecinas entonces muere ( por soledad o sobrepoblacion respectivamente)  </span></span>
<span id="cb3-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">                '''</span></span>
<span id="cb3-20"></span>
<span id="cb3-21">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>:</span>
<span id="cb3-22">                    new_state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb3-23">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elif</span> state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> (n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>):</span>
<span id="cb3-24">                    new_state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb3-25"></span>
<span id="cb3-26">            </span>
<span id="cb3-27"></span>
<span id="cb3-28">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Se actualiza el estado del juego</span></span>
<span id="cb3-29">    state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.copy( new_state_game)</span>
<span id="cb3-30">    plt.matshow(state_game) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># imprimir la matriz con los nuevos estados</span></span>
<span id="cb3-31">    plt.show()</span></code></pre></div></div>
<p>Si nos imaginamos a la matriz como una malla vamos a tener problemas con las celdas que se ubican en los bordes pues no podríamos definir todos sus vecinos. Para solucionar este problema trataremos a la malla como una superficie toroidal es decir que el final de la malla sea el inicio de la malla. Una superficie toroidal es como el video juego Pacman en el cual nuestro amiguito amarillo desaparecía por la izquierda y aparecia por la derecha, de manera similar si desaparece por arriba entonces aparecería por abajo.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/pacman.jpeg" loading="lazy" decoding="async" alt="Pac-Man atraviesa un borde de la pantalla y reaparece en el opuesto" width="483" height="444"></p>
<p>Entonces los vecinos para las celdas del centro (rosados) y de los bordes (azules) quedaria asi.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/xytoroidal.png" loading="lazy" decoding="async" alt="Diagrama de coordenadas vecinas en una cuadrícula toroidal" width="465" height="480"></p>
<p>Si observa el código anterior accedemos a uno de los vecinos usando <code>state_game[(x + 1) % nx_cell, y % ny_cell]</code>, <code>%</code> representa la función resto y es la que nos permite tomar las celdas vecinas para celdas ubicadas en el borde. Por ejemplo basándonos en la imagen anterior , una malla de 10 x 10 en las que iniciamos el conteo de filas y columnas por 0, cuando <code>(x,y)=(9,0)</code>, sus vecinos:</p>
<ol type="1">
<li><code>(x+1,y)=(10%10,0%10)=(0,0)</code></li>
<li><code>(x,y-1)=(9%10,-1%10)=(9,9)</code></li>
<li><code>(x+1,y-1)=(10%10,-1%10)=(0,9)</code></li>
</ol>
<p>Usted puede comprobar en la consola de python que 11%10 es igual a 1 y que -1%10 es 9.</p>
<p>Hasta este punto el algoritmo esta completamente implementado.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">'''GOL.py'''</span></span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pygame</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb4-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#import time</span></span>
<span id="cb4-6"></span>
<span id="cb4-7">nx_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#filas</span></span>
<span id="cb4-8">ny_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#columnas</span></span>
<span id="cb4-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Matriz de estados</span></span>
<span id="cb4-10">state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.randint(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, (nx_cell, ny_cell))</span>
<span id="cb4-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(state_game) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#impresion en consola</span></span>
<span id="cb4-12">plt.matshow(state_game) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#grafico de la matriz de estados</span></span>
<span id="cb4-13">plt.show()</span>
<span id="cb4-14"></span>
<span id="cb4-15"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>:</span>
<span id="cb4-16"></span>
<span id="cb4-17">    new_state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.copy(state_game)</span>
<span id="cb4-18"></span>
<span id="cb4-19">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, nx_cell):</span>
<span id="cb4-20">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> y <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, ny_cell):</span>
<span id="cb4-21"></span>
<span id="cb4-22">            n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-23">                        state_game[x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-24">                        state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-25">                        state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-26">                        state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-27">                        state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-28">                        state_game[x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb4-29">                        state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell]</span>
<span id="cb4-30"></span>
<span id="cb4-31">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">''' Una célula muerta con exactamente 3 células vecinas vivas "nace" (es decir, al turno siguiente estará viva</span></span>
<span id="cb4-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">                Si una célula viva tiene menos de 2 o mas de 3 células vecinas entoncesuere ( por soledad o sobrepoblacion respectivamente)  </span></span>
<span id="cb4-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">            '''</span></span>
<span id="cb4-34"></span>
<span id="cb4-35">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>:</span>
<span id="cb4-36">                new_state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb4-37">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elif</span> state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> (n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>):</span>
<span id="cb4-38">                new_state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb4-39"></span>
<span id="cb4-40">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Se actualiza el estado del juego</span></span>
<span id="cb4-41">    state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.copy(new_state_game)</span>
<span id="cb4-42">    plt.matshow(state_game)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># imprimir la matriz con los nuevos estados</span></span>
<span id="cb4-43">    plt.show()</span></code></pre></div></div>
<p>Si ejecuta el archivo GOL.py empezaran a abrirse ventanas con la imagen del estado de la matriz y estos aparecerán hasta que usted detenga manualmente la ejecución. Aunque el script es funcional, podríamos mejorarlo agregando una interfaz de usuario con atajos de teclado y ratón.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pygame</span>
<span id="cb5-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb5-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb5-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>  time</span>
<span id="cb5-5"></span>
<span id="cb5-6">pygame.init()</span>
<span id="cb5-7">size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> width, height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span></span>
<span id="cb5-8"></span>
<span id="cb5-9">bg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span></span>
<span id="cb5-10"></span>
<span id="cb5-11">nx_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span></span>
<span id="cb5-12">ny_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span></span>
<span id="cb5-13"></span>
<span id="cb5-14">nx_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (width) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> nx_cell</span>
<span id="cb5-15">ny_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (height) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ny_cell</span>
<span id="cb5-16"></span>
<span id="cb5-17">screen <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pygame.display.set_mode(size)</span>
<span id="cb5-18"></span>
<span id="cb5-19">screen.fill(bg)</span>
<span id="cb5-20"></span>
<span id="cb5-21">state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.randint(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, (nx_cell, ny_cell))</span>
<span id="cb5-22"></span>
<span id="cb5-23">state_game[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">19</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-24">state_game[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-25">state_game[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-26"></span>
<span id="cb5-27"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(state_game)</span>
<span id="cb5-28">plt.matshow(state_game)</span></code></pre></div></div>
<p>Una malla la podemos crear dibujando cuadrados sobre un plano cartesiano para lo cual es necesario tener las coordenadas de las esquinas de cada cuadrado que conforma la malla.</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/celdas.png" loading="lazy" decoding="async" alt="Coordenadas cartesianas de las esquinas de una celda de la cuadrícula" width="589" height="553"></p>
<p>Entonces definimos parámetros para que el paquete pygame pueda dibujar:</p>
<ul>
<li><p><code>pygame.init()</code> inicia los módulos importados de pygame</p></li>
<li><p><code>size = width, height = 600</code>, 600 es el tamaño en pixeles de la ventana</p></li>
<li><p><code>bg = 25, 25, 25</code> color de fondo de la ventana</p></li>
<li><p><code>nx_size = (width) / nx_cell</code> tamaño en pixeles del lado x del cuadrado</p></li>
<li><p><code>ny_size = (height) / ny_cell</code> tamaño en pixeles del lado y del cuadrado</p></li>
<li><p><code>screen = pygame.display.set_mode(size)</code> crea una ventana</p></li>
<li><p><code>screen.fill(bg)</code> asigna el color de fondo a la pantalla</p></li>
</ul>
<p>Cuando ejecute el código anterior deberá abrirse una ventana de fondo negro. La malla la dibujamos aprovechando el <code>while</code> y <code>for</code> que creamos para recorrer la matriz de estados.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource python number-lines code-with-copy"><code class="sourceCode python"><span id="cb6-1">PausaGame <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span></span>
<span id="cb6-2"></span>
<span id="cb6-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>:</span>
<span id="cb6-4"></span>
<span id="cb6-5">    new_state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.copy(state_game)</span>
<span id="cb6-6">    screen.fill(bg)</span>
<span id="cb6-7">    time.sleep(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb6-8"></span>
<span id="cb6-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Capturar eventos del teclado y raton</span></span>
<span id="cb6-10"></span>
<span id="cb6-11">    ev <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pygame.event.get()</span>
<span id="cb6-12"></span>
<span id="cb6-13">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print(pygame.KEYDOWN)</span></span>
<span id="cb6-14"></span>
<span id="cb6-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> event <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> ev:</span>
<span id="cb6-16">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> event.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">type</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> pygame.KEYDOWN:</span>
<span id="cb6-17">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> event.key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> pygame.K_ESCAPE:</span>
<span id="cb6-18">                pygame.quit()</span>
<span id="cb6-19">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb6-20"></span>
<span id="cb6-21">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>:</span>
<span id="cb6-22">                PausaGame <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> PausaGame</span>
<span id="cb6-23"></span>
<span id="cb6-24">        mouseClick <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pygame.mouse.get_pressed()</span>
<span id="cb6-25">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print(mouseClick)</span></span>
<span id="cb6-26"></span>
<span id="cb6-27">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(mouseClick)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>:</span>
<span id="cb6-28">            posX, posY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pygame.mouse.get_pos()</span>
<span id="cb6-29">            celdaX, celdaY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(np.floor(posX<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>nx_size)), <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(np.floor(posY<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>ny_size))</span>
<span id="cb6-30">            new_state_game[celdaX, celdaY] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> mouseClick[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb6-31"></span>
<span id="cb6-32">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, nx_cell):</span>
<span id="cb6-33">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> y <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, ny_cell):</span>
<span id="cb6-34"></span>
<span id="cb6-35">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> PausaGame:</span>
<span id="cb6-36">                n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> state_game[(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell ] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-37">                            state_game[x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-38">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-39">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-40">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-41">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-42">                            state_game[x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-43">                            state_game[(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> nx_cell, (y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ny_cell] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb6-44"></span>
<span id="cb6-45">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#print(n_vecinos)</span></span>
<span id="cb6-46"></span>
<span id="cb6-47">                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Una célula muerta con exactamente 3 células vecinas vivas "nace" (es decir, al turno siguiente estará viva)</span></span>
<span id="cb6-48"></span>
<span id="cb6-49">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>:</span>
<span id="cb6-50">                    new_state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb6-51">                <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elif</span> state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> (n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> n_vecinos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>):</span>
<span id="cb6-52">                    new_state_game[x, y] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb6-53"></span>
<span id="cb6-54">            poligonos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [((x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nx_size, (y) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nx_size),</span>
<span id="cb6-55">                         ((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nx_size, (y) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nx_size),</span>
<span id="cb6-56">                         ((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nx_size, (y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ny_size),</span>
<span id="cb6-57">                         ((x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nx_size, (y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ny_size)]  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#coordenadas de los cuadros que crean la malla</span></span>
<span id="cb6-58"></span>
<span id="cb6-59">            pygame.draw.polygon(screen, (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">128</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">128</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">128</span>), poligonos, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>new_state_game[x,y])))</span>
<span id="cb6-60"></span>
<span id="cb6-61">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Se actualiza el estado del juego</span></span>
<span id="cb6-62">    state_game <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.copy( new_state_game)</span>
<span id="cb6-63">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plt.matshow(state_game)</span></span>
<span id="cb6-64">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plt.show()</span></span>
<span id="cb6-65">    pygame.display.flip()</span>
<span id="cb6-66"></span>
<span id="cb6-67"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fin del programa</span></span></code></pre></div></div>
<ul>
<li><p><code>PausaGame</code> nos sirve como variable auxiliar para pausar el juego.</p></li>
<li><p><code>time.sleep(0.1)</code> para que los cambios entre estado se demoren 0.1 ms y podamos observar mejor cómo evoluciona el sistema.</p></li>
<li><p><code>ev = pygame.event.get()</code> sirve para capturar eventos del teclado, es decir cuando se presione alguna tecla.</p></li>
<li><p><code>if event.type == pygame.KEYDOWN:</code> revisa si se presiona alguna tecla.</p></li>
<li><p><code>if event.key == pygame.K_ESCAPE:</code> cuando se ha presionado una tecla, esta linea de codigo pregunta si fue la tecla escape, si esto ha ocurrido entonces el juego se detiene de lo contrario se pausa.</p></li>
<li><p><code>mouseClick = pygame.mouse.get_pressed()</code> captura eventos del raton, es decir si se ha presionado alguno de los botones.</p></li>
<li><p><code>posX, posY = pygame.mouse.get_pos()</code> captura las coordenadas dentro de la ventana donde a dado un clic.</p></li>
<li><p><code>celdaX, celdaY = int(np.floor(posX/nx_size)),int(np.floor(posY/ny_size))</code> transforma las coordenas al numero de celda de la matriz de estados.</p></li>
<li><p><code>new_state_game[celdaX, celdaY] = not mouseClick[2]</code> cambia el estado de la celda con posiciones definidas en la línea anterior.</p></li>
<li><p><code>poligonos</code> son las coordenadas de los cuadrados que se dibujaran para crear la malla.</p></li>
<li><p><code>pygame.draw.polygon(screen, (128, 128, 128), poligonos, int(abs(1-new_state_game[x,y])))</code> dibuja los cuadrados de la malla.</p></li>
<li><p><code>pygame.display.flip()</code> actualiza los fotogramas en la ventana.</p></li>
</ul>
<p>El resultado será</p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/resultado1.gif" loading="lazy" decoding="async" alt="Primera animación de resultado de la implementación del Juego de la Vida" width="294" height="235"></p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/resultado2.gif" loading="lazy" decoding="async" alt="Segunda animación de resultado de la implementación del Juego de la Vida" width="602" height="592"></p>
<p><img src="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/resultado3.gif" loading="lazy" decoding="async" alt="Tercera animación de resultado de la implementación del Juego de la Vida" width="598" height="596"></p>
<p>Puede pausar el juego presionando la barra espaciadora y salir del juego presionando la tecla de escape. También puede dibujar sobre la ventana, primero pause el juego y con el botón izquierdo del ratón pinte las celdas y con el botón derecho las borra.</p>
<p><img src="https://tenor.com/view/bowing-bow-thank-you-thanks-ty-gif-16080496.gif" class="img-fluid" loading="lazy" decoding="async" alt="Animación de agradecimiento al final del artículo"></p>
<p>El código completa se encuentra <a href="https://github.com/DarwinCV/Juego-de-la-vida/blob/master/Juego_de_la_vida.py">aqui</a>.</p>
<p>Si te pareció interesante o al menos entretenido, no olvides compartirlo. Gracias.</p>



 ]]></description>
  <guid>https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/</guid>
  <pubDate>Mon, 15 Jun 2020 00:00:00 GMT</pubDate>
  <media:content url="https://darwincubi.rbind.io/post/2020-06-15-juego-de-la-vida/featured.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
