81 Matching Annotations
  1. Jun 2020
    1. pick <- (courseStructure$學年==acadYear_i & str_detect(courseStructure$應修系級, grade_i)) return( unique(courseStructure$科目名稱[pick])

      SOP一定寫在body裡面

    2. pick <- (courseStructure$學年==acadYear_i & str_detect(courseStructure$應修系級, grade_i)) unique(courseStructure$科目名稱[pick])

      這串是一直重複的,函數的SOP

    3. if(!exists("weather_next36hours")){ jsonlite::fromJSON("https://opendata.cwb.gov.tw/fileapi/v1/opendataapi/F-C0032-001?Authorization=rdec-key-123-45678-011121314&format=JSON") -> weather_next36hours SOAR::Store(weather_next36hours) # 存在.R_cache environment中 }

      askSilly_weather2多了這段

      先設了這個條件:如果我要的"weather_next36hours"物件不存在,才進行下面動作,但進行完後先暫存在使用者看不到的地方(Store())

    4. function本身的運作並不能只靠它的定義值function(...){...},還要有適當的環境(environment)條件才能生存。若物件的生存運作需要有適當的環境,表示電腦要存這個物件時還需要包含(enclose)它的(生存)環境一起存。這種儲存型態叫closure(閉包)。

      電腦要儲存函數本身的值的時候,除了要存他這一連串的定義值以外,他還必須連他能夠存活的環境都要存下來。這種儲存物件值的同時要包含他的生存環境一起存的特殊資料型態,他的type就是closure

    5. # 找出符合地點的天氣資訊:weatherAtLocation (weather_next36hours$cwbopendata$dataset$location$locationName == locationInput) -> pick_location # 可挑出locationInput的「要/不要」向量 weather_next36hours$cwbopendata$dataset$location$weatherElement[pick_location][[1]] -> weatherAtLocation # 在weatherAtLocation找出符合時間的天氣資訊 (weatherAtLocation$elementName=="MaxT") -> pick_MaxT (weatherAtLocation$elementName=="MinT") -> pick_MinT weatherAtLocation$time[pick_MaxT][[1]]$parameter$parameterName[[1]] -> maxT weatherAtLocation$time[pick_MinT][[1]]$parameter$parameterName[[1]] -> minT glue::glue("{locationInput} {dateInput} 氣溫,最高{maxT}度,最低{minT}度。")

      這一整串就是SOP,整串放到function的大括號裡就可以了

    1. middleLevels <- rep(paste0(start, "-", end), each = 2) # 每個新間距要2個

      levels(原始factor) <- ... 中 ...的元素個數要和 左邊levels元素個數一樣多,而5歲變10歲,表示有2個舊間距要用同樣一個新間距。

    2. 以下選法行得通嗎? weather[[1]][[2]]$highest_temp # 今天/新北市/highest_temp weather[[2]][[2]]$highest_temp # 明天/新北市/highest_temp 如果不行,請把weather修改成可以那樣選。

      today <- list(list("台北市",highest_temp = 25, lowest_temp = 18), list("新北市", highest_temp = 24, lowest_temp = 15)) tomorrow <- list(list("台北市", highest_temp = 25, lowest_temp = 18), list("新北市", highest_temp = 24, lowest_temp = 15))

      weather <- list(today, tomorrow)

      print(weather)

    1. factor( c('經濟學系','社會學系','社會學系','經濟學系','經濟學系','社會學系','經濟學系','經濟學系','經濟學系','社會學系') )

      character 先存成factor

  2. May 2020
    1. coercible to one

      如果你放的不是字串向量,然後r有辦法把強迫as.character的話,那也可以,但通常不建議強制轉換,因為可能出現意想不到的東西