openkfw / mapme.protectedareas

Reproducible workflows in R for processing open geodata to create knowledge about KfW supported protected areas and conservation effectiveness.
GNU General Public License v3.0
3 stars 0 forks source link

Create Panel file: code snippets with same object names lead to issue #109

Closed melvinhlwong closed 2 years ago

melvinhlwong commented 2 years ago

@yotaae Could you help on this issue? I am wondering how we did run the code in the past. Below you can see the code line 93-97

https://github.com/openkfw/mapme.protectedareas/blob/0fc17fd383b1442e19cb1fed8855a54a234ba808/analysis/analysis_02_A_createpanel.Rmd#L93-L97

The object name is keys_assetid_wdpa and later in the code (L190-L192) I would need that including the variable "first_year". https://github.com/openkfw/mapme.protectedareas/blob/0fc17fd383b1442e19cb1fed8855a54a234ba808/analysis/analysis_02_A_createpanel.Rmd#L190-L192

Here is the issue: In the lines 141-146 we overwrite keys_assetid_wdpa. And that file does not contain the variable "first_year". Do you know what happened? I am wondering how did we run the code in the past if the variable was missing? Did you made some changes in the order of the code?

https://github.com/openkfw/mapme.protectedareas/blob/0fc17fd383b1442e19cb1fed8855a54a234ba808/analysis/analysis_02_A_createpanel.Rmd#L141-L146

yotaae commented 2 years ago

@melvinhlwong. Two things come to mind:

  1. I believe lines 141-146 are within the code chunk for loading disbursement data. I have disabled the evaluation (see eval=FALSE) of this file because it just took too long to run (in my case at least). So when I ran the code, I don't remember it causing problems.

  2. In lines 93-97 I loaded keys_assetid_wdpa but I also joined it with wdpa_year. This is where first_year is coming from. If you need first_year later in the code, I think we could join keys_assetid_wdpa with wdpa_year in the disbursement data chunk or we could just cut the keys_assetid_wdpa loading part from lines 93-97 and insert it after the disbursement chunk, e.g. in line 180 in a new chunk.

Hope that helps.

melvinhlwong commented 2 years ago

@yotaae thanks you! Your first point is 100% true. Super happy. I think I need to delete that code chunk or use it differently.