def update_func_matches(self): """Update function matches if necessary""" if self.update_loaded_pkgs(): self._info('Update loaded R packages: %s', self._pkg_loaded) funcs = filtr.pkg(self._all_matches, self._pkg_loaded) funcs = filtr.struct(funcs, 'function') self._fnc_matches = funcs
def get_data_matches(self): """Return list of matches with datasets from R packages""" pkg_matches = filtr.pkg(self._all_matches, self._pkg_loaded) data = filtr.struct(pkg_matches, 'data.frame') data.extend(filtr.struct(pkg_matches, 'tbl_df')) return data
def get_matches(self, word, pkg=None, pipe=None, data=None): """Return function and object matches based on given word :word: string to filter matches with :pkg: only show functions from R package :pipe: piped data :returns: list of ncm matches """ self.get_all_obj_matches() obj_m = self._obj_matches if pipe or data: # Inside data pipeline or data brackets, keep variables from piped # data dataframe = pipe if pipe else data obj_m = filtr.word(obj_m, dataframe + '$', rm_typed=True) if data: obj_m = add_snippet_var_inside_brackets(obj_m) else: if '$' in word: # If we're looking inside a data frame or tibble, only return # its variables obj_m = filtr.word(obj_m, word, rm_typed=True) else: # Otherwise, hide what's inside data.frames obj_m = filtr.word(obj_m, word, hide='$') matches = obj_m # Get functions from loaded R packages self.update_func_matches() func_m = filtr.pkg(self._fnc_matches, pkg) if not pkg: func_m.extend(self._pkg_matches) if not pkg or (pkg and word): func_m = filtr.word(func_m, word) matches.extend(func_m) return matches