tpemartin / 109-2-app101

https://tpemartin.github.io/109-2-app101/
1 stars 10 forks source link

古蹟挑選 #66

Closed chao87119 closed 3 years ago

chao87119 commented 3 years ago

將年份已經處理好的heritage data , 以給定的時間條件,篩選出符合的古蹟

https://github.com/tpemartin/109-2-app101/blob/main/weekly_progress/selectHeritage_byTime.Rmd 完成下列三個 function :
                 i. filter_heritage                    將有包含start , end 年份區間的古蹟篩選出來                  ii. exist_since                    將給定年份之後的古蹟挑選出來                  iii. exist_before                    將給定年份之前的古蹟挑選出來

Note :
     1. 古蹟年份轉換可參考 #64 #58      2. 我記得好像會用到lubridate
     3. https://github.com/tpemartin/109-2-app101/blob/main/R/chinese_martin.R

負責人 : @chao87119 @Simmonslin @yuhong69 @jilufu @want180

chao87119 commented 3 years ago

chinese_martin.R

裡面有一個需要修正的地方

chinese$convert_chnWesternYears <- convert_chnWesternYears <- function(chnWestYears){
  stringr::str_remove(chnWestYears, "年") -> .temp
  convert_chn2arabics(.temp) -> .temp
  stringr::str_replace_all(.temp,c("0"="0","○"="0","O"="0")) -> .temp  #加入這行
  as.integer(.temp) -> westernYearInteger
  return(westernYearInteger)
}
chao87119 commented 3 years ago

chinese_martin.R

裡面有一個需要修正的地方

chinese$convert_chnWesternYears <- convert_chnWesternYears <- function(chnWestYears){
  stringr::str_remove(chnWestYears, "年") -> .temp
  convert_chn2arabics(.temp) -> .temp
  stringr::str_replace_all(.temp,c("0"="0","○"="0","O"="0")) -> .temp  #加入這行
  as.integer(.temp) -> westernYearInteger
  return(westernYearInteger)
}

修改

chinese$convert_chnWesternYears <- convert_chnWesternYears <- function(chnWestYears){
  stringr::str_remove(chnWestYears, "年") -> .temp
  convert_chn2arabics(.temp) -> .temp
  stringr::str_replace_all(.temp,c("0"="0","○"="0","O"="0","O"="0")) -> .temp  #更改這行
  as.integer(.temp) -> westernYearInteger
  return(westernYearInteger)
}
chinese$convert2westernYears <- function(list_heritageYearsX){
  pattern_mingou <- "民國"
  pattern_chnWestern <- "一[○O0O0一二三四五六七八九十]{3}"   #更改這行
  pattern_jpn <- "日[治據]時[期代]"
chao87119 commented 3 years ago

https://github.com/chao87119/109-2-app101/blob/main/weekly_progress/frank/time_interval.R https://github.com/chao87119/109-2-app101/blob/main/weekly_progress/frank/select_heritage.Rmd

Simmonslin commented 3 years ago

請問各位都能夠引入chinese模組嗎?我無法引入模組,然後會出現 -->Error in file(filename, "r", encoding = encoding) : 無法開啟連結的字串

yuhong69 commented 3 years ago

請問各位都能夠引入chinese模組嗎?我無法引入模組,然後會出現 -->Error in file(filename, "r", encoding = encoding) : 無法開啟連結的字串

我個人是可以引入,但不能用 後來先用自己之前做的修正資料 但顯然至今尚未完成整個 code

不過可以先點到 .R 檔 按上面的 source 下面 console 會給你正確的路徑 但我記得要加 , encoding = "UTF-8" 才對

我個人引入長這樣(抄老師的,只是路徑改成我自己的 .R) .root <- rprojroot::is_rstudio_project$make_fix_file() source(file.path(.root(),"weekly_progress/yuhong/transfer_to_num_list.R"),encoding = "UTF-8")

chao87119 commented 3 years ago

請問各位都能夠引入chinese模組嗎?我無法引入模組,然後會出現 -->Error in file(filename, "r", encoding = encoding) : 無法開啟連結的字串

你可以直接複製你的檔案路徑,像是 source("/Users/frankchao/Desktop/109-2-app101/R/chinese_martin.R")

chao87119 commented 3 years ago

轉換data方法

引入chinese module

.root <- rprojroot::is_rstudio_project$make_fix_file()
source(
  file.path(.root(),"R/chinese_martin.R")
)

轉換data

purrr::map(
  list_heritageYears,
  ~{
    chinese$convert2westernYears(.x)
  }
) -> list_heritageYears_converted
Simmonslin commented 3 years ago

@chao87119 你跑轉換data那段不會出現無效的多位元組字串的Error嗎? 我的只能改到list_heritageYears[[59]],第60列會因為民國卅年直接Error掉,還在想辦法解決

chao87119 commented 3 years ago

@chao87119 你跑轉換data那段不會出現無效的多位元組字串的Error嗎? 我的只能改到list_heritageYears[[59]],第60列會因為民國卅年直接Error掉,還在想辦法解決

方便放一下code嗎 我這邊沒問題

Simmonslin commented 3 years ago
purrr::map(
  list_heritageYears,
  ~{
    chinese$convert2westernYears(.x)

  }
) -> list_heritageYears_converted

library(stringr)

for (i in 1:length(list_heritageYears)){

  if (length(list_heritageYears[[i]])>0){

    list_heritageYears[[i]][str_detect(list_heritageYears[[i]],pattern_mingou)]<-chinese$convert2westernYears(list_heritageYears[[i]][str_which(list_heritageYears[[i]], pattern_mingou)]) 

    list_heritageYears[[i]][str_detect(list_heritageYears[[i]],pattern_chnWestern)]<-chinese$convert2westernYears(list_heritageYears[[i]][str_which(list_heritageYears[[i]], pattern_chnWestern)]) 

    list_heritageYears[[i]][str_detect(list_heritageYears[[i]],pattern_jpn )]<-chinese$convert2westernYears(list_heritageYears[[i]][str_which(list_heritageYears[[i]],pattern_jpn)]) 

  }

}

View(list_heritageYears)

然後兩個的Error都是Error in chinese$convert_minguo2western(list_heritageYearsX[whichAreMingou]) : 無效的多位元組字串

(第1個跟你的寫法完全一樣,但到60列就error了)

chao87119 commented 3 years ago
purrr::map(
  list_heritageYears,
  ~{
    chinese$convert2westernYears(.x)

  }
) -> list_heritageYears_converted

library(stringr)

for (i in 1:length(list_heritageYears)){

  if (length(list_heritageYears[[i]])>0){

    list_heritageYears[[i]][str_detect(list_heritageYears[[i]],pattern_mingou)]<-chinese$convert2westernYears(list_heritageYears[[i]][str_which(list_heritageYears[[i]], pattern_mingou)]) 

    list_heritageYears[[i]][str_detect(list_heritageYears[[i]],pattern_chnWestern)]<-chinese$convert2westernYears(list_heritageYears[[i]][str_which(list_heritageYears[[i]], pattern_chnWestern)]) 

    list_heritageYears[[i]][str_detect(list_heritageYears[[i]],pattern_jpn )]<-chinese$convert2westernYears(list_heritageYears[[i]][str_which(list_heritageYears[[i]],pattern_jpn)]) 

  }

}

View(list_heritageYears)

然後兩個的Error都是Error in chinese$convert_minguo2western(list_heritageYearsX[whichAreMingou]) : 無效的多位元組字串

(第1個跟你的寫法完全一樣,但到60列就error了)

還是你把data清掉 , 重試一次看看

Simmonslin commented 3 years ago

@chao87119 問題出在模組中的 tenth <- stringr::str_extract(non_arabics, "一二三四五六七八九壹貳參肆伍陸柒捌玖")上,?=是甚麼意思? 現在想改看看

chao87119 commented 3 years ago

@chao87119 問題好像有點複雜,只要涉及民國四十開頭或六十開頭的年份全部是無效字串 民國卅七年則是在模組中就找不到參數non_arabics了

無效字串好像是encoding問題 可能一開始引入資料就有問題?

Simmonslin commented 3 years ago

@chao87119 試過了,一開始引入模組就加上encoding=UTF-8了,用BIG5無法引入模組

.root <- rprojroot::is_rstudio_project$make_fix_file()
source( 
  file.path(.root(),"weekly_progress/Simmons/chinese_martin.R"),encoding="UTF-8")
chao87119 commented 3 years ago

@chao87119 問題出在模組中的 tenth <- stringr::str_extract(non_arabics, "一二三四五六七八九壹貳參肆伍陸柒捌玖")上,?=是甚麼意思? 現在想改看看

?=[十拾]|0 代表後面是十or拾or0

Simmonslin commented 3 years ago

@chao87119 哭啊後來檢查也不是模組的問題,現在完全不知道為什麼四十跟六十無效了

chao87119 commented 3 years ago

@chao87119 哭啊後來檢查也不是模組的問題,現在完全不知道為什麼四十跟六十無效了

會不會 list_heritageYears 就錯了 不過這樣你之前應該也不能用才對

Simmonslin commented 3 years ago

試過民國四十幾、六十幾之外的全部能改,然後民國初年、...多餘年、民國前幾年都能改,就只有中文四跟六的十進位跟卅沒辦法改,chinese_Martin.R的debug全跑過也沒問題,已經不是程式的問題了

tpemartin commented 3 years ago

試過民國四十幾、六十幾之外的全部能改,然後民國初年、...多餘年、民國前幾年都能改,就只有中文四跟六的十進位跟卅沒辦法改,chinese_Martin.R的debug全跑過也沒問題,已經不是程式的問題了

@Simmonslin 可否放上產生這錯誤的 code 在github上,然後在github.com進到錯誤產生那行產生一個permalink,然後把permalink貼過來這裡方便大家能在電腦上跑你的code.

Screen Shot 2021-05-26 at 9 58 51 AM
jilufu commented 3 years ago

我的也沒辦法引入,然後我點到 .R檔的 source 在console 就會跑出 Error in -title : 一元運算子的引數不正確 想問這是甚麼意思~~~

want180 commented 3 years ago

我的也沒辦法引入,他一直寫錯誤,但我是從檔案的內容直接複製的,還有改斜線,而且我對照了上面的程式碼,想請問要怎麼辦

.root <- rprojroot::is_rstudio_project$make_fix_file()
source(
  file.path(.root()," C:/Users/DELL/Deskto/R/Github/109-2-app101/R/chinese_martin.R", encoding = "UTF-8)
)
tpemartin commented 3 years ago

我的也沒辦法引入,他一直寫錯誤,但我是從檔案的內容直接複製的,還有改斜線,而且我對照了上面的程式碼,想請問要怎麼辦

.root <- rprojroot::is_rstudio_project$make_fix_file()
source(
  file.path(.root()," C:/Users/DELL/Deskto/R/Github/109-2-app101/R/chinese_martin.R", encoding = "UTF-8)
)

@want180 .root() 會產生 "c:/...../109-2-app101", 所以你可以把.root()拿掉,但你的C:前面還有空一格。

yuhong69 commented 3 years ago

.root ‹- 那行的意思是我們這個專案(109-2-app101)在本機的路徑 因為每個人檔案位置都不一樣 用 rprojroot 的那個函數可以抓到路徑 確保每個人開都可以重新抓一次(開別人檔案也可以抓到自己本機正確的路徑)

所以第二句 source 導入 .root 就已經一路到/101-2-app101/了,後面只要補R/...就可以了 可以用士賢三天前的回覆應該是沒問題的

如果是自己跑的話(其他人不能跑)也可以像老師說的 只要第二句就好 也不用 .root 直接用自己本機的路徑就可以

want180 commented 3 years ago

我把.root拿掉後還是顯示錯誤耶...

yuhong69 commented 3 years ago

@want180 有把 C 前面的空格拿掉嗎 UTF-8 後面也缺” 這樣應該可以: source( "C:/Users/DELL/Deskto/R/Github/109-2-app101/R/chinese_martin.R", encoding = "UTF-8”)

want180 commented 3 years ago

他說無法開啟連結@@

tpemartin commented 3 years ago

@want180 , 麻煩執行 list.files("C:/Users/DELL/Deskto/R/Github/109-2-app101/R/") 再回傳你看到的結果

yuhong69 commented 3 years ago

@want180 那可以試試直接點到那個 .R 檔 點上面的 source 應該是可以的 其實有點的話, global environment 就有 function 了可以先往下做(?) 另外,點了下面 console 也會給你 source 那行

沒事你聽老師ㄉ

tpemartin commented 3 years ago

@yuhong69 很熱心,很棒。 不需要跳過你的建議,每個人的建議都值得try try.

want180 commented 3 years ago

感謝老師感謝大家 跑出來了!

Simmonslin commented 3 years ago
  1. https://github.com/Simmonslin/109-2-app101/blob/a62ebe7be3fe8efe7597db5b982be69f7bc1ae28/weekly_progress/Simmons/time_interval.Rmd#L61
  1. https://github.com/Simmonslin/109-2-app101/blob/21e27e591c99c91e0fda92831adaa53e8db4a9f0/weekly_progress/Simmons/time_interval.Rmd#L97
yuhong69 commented 3 years ago

https://github.com/yuhong69/109-2-app101/blob/main/weekly_progress/yuhong/05-20-selectHeritage_byTime.Rmd